以下代码会引发编译错误
不能在 return 语句中使用 ExampleProps(Props[Example] 类型的变量)作为 Props[Generic] 值
// Abstract
type Generic interface {
ID() string
}
type Props[G Generic] struct{}
// Example
type Example struct {
id string
}
func (example Example) ID() string {
return example.id
}
var ExampleProps = Props[Example]{}
// Problem
func Problem() Props[Generic] {
return ExampleProps
}
Run Code Online (Sandbox Code Playgroud)
我的问题是:作为Example
实现Generic
,为什么Go不允许分配Props[Example]
给Props[Generic]
?