Let's supposed I've got the following interface and two structs that implement it:
type Tmp interface {
MyTmp() string
}
type MyStructA struct {
ArrayOfItems []int
}
func (a MyStructA) MyTmp() string {
return "Hello World"
}
type MyStructB struct {
ArrayOfItems []int
}
func (a MyStructB) MyTmp() string {
return "Hello World B"
}
As you notice both MyStructA
and MyStructB
implement Tmp
and both have a property named ArrayOfItems. Using the interface signature, how could I iterate over that property which both have? Something similar to:
func (c ADifferentStruct) iterate(myTmp Tmp) {
for _, number := range myTmp.ArrayOfItems {
fmt.Println(number)
}
}
NOTE: I don't want to add another method to the interface (ie getter/setters) to process or to define ArrayOfItems
is this possible?