Created
June 27, 2019 09:35
-
-
Save baijum/820945718e94c336cb96387b246a4bc8 to your computer and use it in GitHub Desktop.
interface implements
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 myInterace interface { | |
| Hello() string | |
| } | |
| type myStruct struct{} | |
| func (m myStruct) Hello() string { | |
| return "Hello 1" | |
| } | |
| func say(mi myInterace) { | |
| fmt.Println(mi.Hello()) | |
| } | |
| var _ myInterace = myStruct{} | |
| type newStruct struct{} | |
| var _ myInterace = newStruct{} | |
| func main() { | |
| m1 := myStruct{} | |
| say(m1) | |
| /* | |
| n1 := newStruct{} | |
| say(n1) | |
| */ | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment