FAQ
Just a guess, but maybe:

Create a type:

type CToB struct {
*C
}

func (c CToB) Get() A {
return c.C.Get()
}


Or:

type CToB struct {
C interface {
Get() *CA
}
}


And call it like this:

func main() {
var c interface{} = CToB{&C{}}
d := c.(B)
fmt.Println(d.Get().AAA())
fmt.Println("Hello, playground")
}



On Wednesday, July 29, 2015 at 7:14:20 AM UTC-7, mission liao wrote:

Hi,

I'm curious of the conversion of interfaces. Here is the example
http://play.golang.org/p/i0cOBhpAym
In that example,
interface B defines a method returning an interface A, and
struct C implement a method returning a pointer to struct CA which
implements interface A.

I wonder why Go can't deduce interface B from C.
If *interface A, B* and *struct C, CA* are in different package, then
the only way to make it possible is either
- refine the method of *C.Get* to *func Get() A*, this means I need
to import the definition of interface A from other package and introduce
more dependency, or
- refine the method *Get* of C and B to *func Get() interface{}*

Can anyone give me some hint or clue?

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Search Discussions

Discussion Posts

Previous

Follow ups

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 3 of 4 | next ›
Discussion Overview
groupgolang-nuts @
categoriesgo
postedJul 29, '15 at 2:14p
activeJul 30, '15 at 4:59a
posts4
users4
websitegolang.org

People

Translate

site design / logo © 2021 Grokbase