https://play.golang.org/p/IMWd3cvgfsU
// also replicated below
package main
import (
"fmt"
)
type (
T1 interface{ f1()int; f2()int }
T2 interface{ f2()int; f3()int }
)
type C int
func (c C)f1()int {return 1}
func (c C)f2()int {return 2}
func (c C)f3()int {return 3}
func main() {
var (x1 T1; x2 T2; c C; o interface{})
fmt.Printf("%T, %T, %T, %T\n", x1, x2, o, c)
p(x1);p(x2);p(o);p(c)
x1 = c; x2 = c; o = c
fmt.Printf("%T, %T, %T, %T\n", x1, x2, o, c)
p(x1);p(x2);p(o);p(c)
}
func p(o interface{}) {
switch o.(type) {
case T1: fmt.Println("T1")
case T2: fmt.Println("T2")
case C: fmt.Println("C")
case interface{}: fmt.Println("interface{}")
default: fmt.Println("<nil>?")
}
}
The output is
<nil>, <nil>, <nil>, main.C
<nil>?
<nil>?
<nil>?
T1 <<==
main.C, main.C, main.C, main.C
T1
T1 <<==
T1 <<==
T1 <<==
In particular I don't undertand the lines marked with <<==.
--
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 [email protected].
For more options, visit https://groups.google.com/d/optout.