Reflection thing from Jesse :-)
This commit is contained in:
parent
44999623da
commit
39fdd6fdd6
@ -14,7 +14,9 @@ TARGETS = \
|
|||||||
github.com/meatballhat/box-o-sand/gotime/gotour-artifacts/maps \
|
github.com/meatballhat/box-o-sand/gotime/gotour-artifacts/maps \
|
||||||
github.com/meatballhat/box-o-sand/gotime/gotour-artifacts/ranges \
|
github.com/meatballhat/box-o-sand/gotime/gotour-artifacts/ranges \
|
||||||
github.com/meatballhat/box-o-sand/gotime/gotour-artifacts/selects \
|
github.com/meatballhat/box-o-sand/gotime/gotour-artifacts/selects \
|
||||||
github.com/meatballhat/box-o-sand/gotime/junkdrawer/greppish
|
github.com/meatballhat/box-o-sand/gotime/junkdrawer/greppish \
|
||||||
|
github.com/meatballhat/box-o-sand/gotime/junkdrawer/reflectish
|
||||||
|
|
||||||
|
|
||||||
test: build
|
test: build
|
||||||
go test -x -v $(TARGETS)
|
go test -x -v $(TARGETS)
|
||||||
|
41
gotime/junkdrawer/reflectish/main.go
Normal file
41
gotime/junkdrawer/reflectish/main.go
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"reflect"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Fooer interface {
|
||||||
|
Foo(int) int
|
||||||
|
}
|
||||||
|
|
||||||
|
type Bar struct {
|
||||||
|
SomeField int
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *Bar) Foo(x int) int {
|
||||||
|
return x
|
||||||
|
}
|
||||||
|
|
||||||
|
type Baz struct {
|
||||||
|
SomeField int
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this Baz) Foo(x int) int {
|
||||||
|
return x
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
var bar, baz Fooer
|
||||||
|
|
||||||
|
bar = &Bar{
|
||||||
|
SomeField: 5,
|
||||||
|
}
|
||||||
|
|
||||||
|
baz = Baz{
|
||||||
|
SomeField: 5,
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Println(reflect.ValueOf(baz).FieldByName("SomeField"))
|
||||||
|
fmt.Println(reflect.Indirect(reflect.ValueOf(bar)).FieldByName("SomeField"))
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user