| // Suppose: | |
| var ai AbsInterface // declares method Abs() | |
| type SqrInterface interface { Sqr() float } | |
| var si SqrInterface | |
| pp := new(Point) // say *Point implements Abs, Sqr | |
| var empty interface{} | |
| // Then the following statements and type assertions are valid: | |
| empty = pp; // everything satisfies empty | |
| ai = empty.(AbsInterface); // underlying value pp implements Abs() | |
| // (runtime failure otherwise) | |
| si = ai.(SqrInterface); // *Point has Sqr() even though AbsInterface doesn’t | |
| empty = si; // *Point implements empty set | |
| // Note: statically checkable so type assertion not necessary. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment