Created
August 4, 2015 03:05
-
-
Save hnsl/03e5953ec151558583cc to your computer and use it in GitHub Desktop.
golang interface experiments
This file contains 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
type count int32 | |
type incrementable interface { | |
Inc() | |
} | |
type countable interface { | |
incrementable | |
Dec() | |
} | |
func f(x countable) { | |
x.Inc() | |
x.Dec() | |
x.Dec() | |
} | |
/*func (x count) Inc() { | |
x = x + 1 | |
}*/ | |
func (x *count) Inc() { | |
*x = *x + 1 | |
} | |
func (x *count) Dec() { | |
*x = *x - 1 | |
} | |
func main() { | |
var x count = 4 | |
f(&x) | |
os.Exit(int(x)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment