Last active
September 1, 2017 14:18
-
-
Save polidog/f0906f821afca6652e3d32613b91ddcb to your computer and use it in GitHub Desktop.
interface+pointer sample
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 Hoge interface { | |
Flush() | |
} | |
type Fuga struct { | |
Count int | |
} | |
func (f *Fuga) Flush() { | |
f.Count++ | |
fmt.Println("flush: ", f.Count) | |
} | |
func (f Fuga) DisplayCount() { | |
fmt.Println("count: ", f.Count) | |
} | |
func Call(h Hoge) { | |
h.Flush() | |
} | |
func Call2(f Fuga) { | |
f.Flush() | |
} | |
func main() { | |
f := &Fuga{} | |
Call(f) | |
Call(f) | |
Call(f) | |
Call2(*f) | |
f.DisplayCount() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment