On Saturday, October 8, 2016 at 9:14:34 PM UTC+8, Fei Ding wrote: > > Recently I've been asked a question which is, what's the difference > between Golang and Java about *interface*? > > > I know there are some 'syntax-sugar level' differences, what I am > interested is anything beneath the ground, like how does Golang and Java > implement interface? What's the biggest difference? Which one is more > efficient? Why? > > > Could anyone post blog links or source code about this topic? The only > code I can find is in src/runtime/iface.go, but I cannot understand it or > get anything useful by myself yet. Source code is better. > > > Thanks. >
In golang, you can convert one interface value to another interface value: ackage main import "fmt" type I0 interface { IsZero() bool } type I1 interface { IsOne() bool } type T int func (t T) IsZero() bool { return t == 0 } func (t T) IsOne() bool { return t == 1 } func main(){ var i0 I0 = T(1) var i1 = i0.(I1) fmt.Println(i1.IsOne()) } -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.