接口方法引用相同的接口?
我是一名java程序员,我现在正在学习go。 我尝试编写一个名为 Vo 的自嵌套接口,以及一个名为 Score 的 Vo 实现, 像这样的代码:
type Vo interface {
Merge(v Vo) Vo
}
type Score int
func (this Score) Merge(s Score) Score {
return Score(this + s)
}
func TestThePkg(t *testing.T) {
s := Score(5)
var v Vo = s //compile error
}
详细的编译错误是:
cannot use s (variable of type Score) as Vo value in variable declaration: Score does not implement Vo (wrong type for method Merge)
have Merge(s Score) Score
want Merge(v Vo) VocompilerInvalidIfaceAssign
如何解决这个问题? 谢谢!
i'm a java programer ,i'm learing go now.
i try to wirte a self nested interface named Vo,and a implemention of Vo named Score,
code like this:
type Vo interface {
Merge(v Vo) Vo
}
type Score int
func (this Score) Merge(s Score) Score {
return Score(this + s)
}
func TestThePkg(t *testing.T) {
s := Score(5)
var v Vo = s //compile error
}
detail compile error is :
cannot use s (variable of type Score) as Vo value in variable declaration: Score does not implement Vo (wrong type for method Merge)
have Merge(s Score) Score
want Merge(v Vo) VocompilerInvalidIfaceAssign
how to resolve this problem?
thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
游乐场
play ground