Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- type Foo struct{}
- func (foo *Foo) DoStuffWithPointer() {}
- func (foo Foo) DoStuffWithCopy() {}
- func TestFoo(t *testing.T) {
- foo := Foo{};
- pFoo := &Foo{};
- fooType := reflect.Typeof(foo);
- pFooType := reflect.Typeof(pFoo);
- foo.DoStuffWithPointer();
- pFoo.DoStuffWithPointer();
- foo.DoStuffWithCopy();
- pFoo.DoStuffWithCopy();
- fmt.Println("Foo has", fooType.NumMethod(), "methods");
- fmt.Println("*Foo has", pFooType.NumMethod(), "methods");
- }
- // Output:
- // Foo has 1 methods
- // *Foo has 2 methods
- // Yet both Foo and *Foo can call both methods.
Add Comment
Please, Sign In to add comment