Junior — Senior
Checking the possibility of converting one interface to another in Go
livecode
Task condition
You need to understand what result the program will produce. Question: Is it permissible to perform a type assertion from one interface to another, and will this lead to a panic at runtime, or will the methods be successfully called?
type Foo struct{}
func (f *Foo) A() {}
func (f *Foo) B() {}
func (f *Foo) C() {}
type AB interface {
A()
B()
}
type BC interface {
B()
C()
}
func main() {
var a int
var f AB = &Foo{}
y := f.(BC) // will this type assertion work?
y.A() // and this call?
_ = y
}