| 1 | package main |
| 2 | |
| 3 | import ( |
| 4 | "fmt" |
| 5 | ) |
| 6 | |
| 7 | type X struct{} |
| 8 | |
| 9 | func (X) Foo() int { |
| 10 | return 1 |
| 11 | } |
| 12 | func (X) Bar() int { |
| 13 | return 2 |
| 14 | } |
| 15 | |
| 16 | type Foo interface { |
| 17 | Foo() int |
| 18 | } |
| 19 | type Bar interface { |
| 20 | Bar() int |
| 21 | } |
| 22 | |
| 23 | func main() { |
| 24 | var x X |
| 25 | var i Foo = x |
| 26 | j := i.(Bar) |
| 27 | |
| 28 | fmt.Println(j.Bar()) |
| 29 | } |
| 30 | |
| 31 | // Output: |
| 32 | // 2 |