Created
March 12, 2015 04:51
-
-
Save hollingberry/66d4270b190ed7a8e31e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
) | |
type Banana struct { | |
msg string | |
} | |
func (b *Banana) MethodWithPointerReceiver() { | |
fmt.Println("Pointer receiver with ", b.msg) | |
} | |
func (b Banana) MethodWithNonPointerReceiver() { | |
fmt.Println("Non-pointer receiver with ", b.msg) | |
} | |
func main() { | |
pointerBanana := &Banana{"a pointer banana"} | |
nonPointerBanana := Banana{"a non-pointer banana"} | |
pointerBanana.MethodWithPointerReceiver() | |
pointerBanana.MethodWithNonPointerReceiver() | |
nonPointerBanana.MethodWithPointerReceiver() | |
nonPointerBanana.MethodWithNonPointerReceiver() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment