Skip to content

Instantly share code, notes, and snippets.

@kokardy
Created September 23, 2013 07:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kokardy/6667441 to your computer and use it in GitHub Desktop.
Save kokardy/6667441 to your computer and use it in GitHub Desktop.
interface型でない変数の型アサーション ref: http://qiita.com/kokardy/items/d3be8f8081f1a4438cc7
t, ok := x.(T)
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