How to implement interface method with return type is an interface in Golang

Just change

func (a *A) FB() *B {
    return a.b
}

into

func (a *A) FB() IB {
    return a.b
}

Surely IB can be defined in another package. So if both interfaces are defined in package foo and the implementations are in package bar, then the declaration is

type IA interface {
    FB() IB
}

while the implementation is

func (a *A) FB() foo.IB {
    return a.b
}

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)