Source file
test/reflectmethod2.go
1
2
3
4
5
6
7
8
9
10
11 package main
12
13 import reflect1 "reflect"
14
15 var called = false
16
17 type M int
18
19 func (m M) UniqueMethodName() {
20 called = true
21 }
22
23 var v M
24
25 type MyType interface {
26 MethodByName(string) (reflect1.Method, bool)
27 }
28
29 func main() {
30 var t MyType = reflect1.TypeOf(v)
31 m, _ := t.MethodByName("UniqueMethodName")
32 m.Func.Interface().(func(M))(v)
33 if !called {
34 panic("UniqueMethodName not called")
35 }
36 }
37
View as plain text