I have a "main type" and a "sub-type" is embedded in that.Both main and sub implements an interface.
When I'm assigning a 'main type' variable to interface type variable and call implemented method using that interface variable,It calls "main type" implementation not sub type's.I need to call sub-types implementation.
Is it possible in GO ? I think my code design is having some problem. Here I'm giving a sample code to describe this problem.
package main
import "fmt"
type interf interface{
typeCheck()
}
type maintype struct{
subtype
}
type subtype struct {}
func (maintype) typeCheck () {
fmt.Println("Hi,this is printed in Main type")
}
func (subtype) typeCheck () {
fmt.Println("Hi,this is printed in Sub-type")
}
func main() {
var intr interf
var maintp maintype
intr = maintp
intr.typeCheck()//Out :"Hi,this is printed in Main type" I need "Hi,this is printed in Sub-type"
}
PlayGround : http://play.golang.org/p/ut5XPiED75
Kindly Help....