github.com/traefik/yaegi@v0.15.1/_test/interface46.go (about)

     1  package main
     2  
     3  import "fmt"
     4  
     5  type I interface {
     6  	Foo() string
     7  }
     8  
     9  type Printer struct {
    10  	i I
    11  }
    12  
    13  func New(i I) *Printer {
    14  	return &Printer{
    15  		i: i,
    16  	}
    17  }
    18  
    19  func (p *Printer) Print() {
    20  	fmt.Println(p.i.Foo())
    21  }
    22  
    23  type T struct{}
    24  
    25  func (t *T) Foo() string {
    26  	return "test"
    27  }
    28  
    29  func main() {
    30  	g := New(&T{})
    31  	g.Print()
    32  }
    33  
    34  // Output:
    35  // test