Skip to content

Instantly share code, notes, and snippets.

@wyyqyl
Created December 4, 2014 15:24
Show Gist options
  • Save wyyqyl/44b8e675acaf72e2ba8b to your computer and use it in GitHub Desktop.
Save wyyqyl/44b8e675acaf72e2ba8b to your computer and use it in GitHub Desktop.
Example of type assertion failure
package main
import (
"fmt"
)
type Aer interface {
DoA()
}
type Ber interface {
DoB()
}
type A bool
func (a A) DoA() {
fmt.Println("A.DoA")
}
func main() {
defer func() {
if x := recover(); x != nil {
fmt.Println(x)
}
}()
var a A
var aer Aer
aer = a
aer.DoA()
var ber Ber
// interface conversion failed
ber = aer.(Ber)
ber.DoB()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment