Created
September 23, 2013 07:31
-
-
Save kokardy/6667441 to your computer and use it in GitHub Desktop.
interface型でない変数の型アサーション ref: http://qiita.com/kokardy/items/d3be8f8081f1a4438cc7
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
t, ok := x.(T) |
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 Tester interface { | |
Test() | |
} | |
type A struct{} | |
func (a A) Test() { | |
fmt.Println("called A.Test()") | |
} | |
func main() { | |
a := new(A) | |
tester, ok := interface{}(a).(Tester) | |
//tester, ok := a.(Tester) //ERROR! | |
fmt.Println("a is a Tester:", ok) | |
tester.Test() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment