Guest User

Untitled

a guest
Jul 19th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.56 KB | None | 0 0
  1. type Foo struct{}
  2.  
  3. func (foo *Foo) DoStuffWithPointer() {}
  4.  
  5. func (foo Foo) DoStuffWithCopy() {}
  6.  
  7. func TestFoo(t *testing.T) {
  8. foo := Foo{};
  9. pFoo := &Foo{};
  10. fooType := reflect.Typeof(foo);
  11. pFooType := reflect.Typeof(pFoo);
  12. foo.DoStuffWithPointer();
  13. pFoo.DoStuffWithPointer();
  14. foo.DoStuffWithCopy();
  15. pFoo.DoStuffWithCopy();
  16. fmt.Println("Foo has", fooType.NumMethod(), "methods");
  17. fmt.Println("*Foo has", pFooType.NumMethod(), "methods");
  18. }
  19.  
  20.  
  21. // Output:
  22. // Foo has 1 methods
  23. // *Foo has 2 methods
  24. // Yet both Foo and *Foo can call both methods.
Add Comment
Please, Sign In to add comment