* d...@veryhaha.com <d...@veryhaha.com> [161013 08:42]: > https://golang.org/ref/spec#Type_assertions > > var x interface{} = 7 // x has dynamic type int and value 7 > i := x.(int) // i has type int and value 7 > > type I interface { m() } > var y I > s := y.(string) // illegal: string does not implement I (missing > method m) > r := y.(io.Reader) // r has type io.Reader and y must implement > both I and io.Reader > > I don't understand the comment of the last line. Can someone explain it for > me?
To expand on what Jan Mercl said, the spec separates x.(T) into two cases: T is not an interface type, and T is an interface type. The example above (from the spec) is giving an example of each case. The compiler can detect the first case, but the second case must be checked at runtime. ...Marvin -- 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.