For example after embedding the parent struct in the child struct:
type ParentNode struct {
}
type ChildNode struct {
ParentNode
Ident string
}
func ParentType() ParentNode {
child := ChildNode{Ident : "node"}
fmt.Println(child)
return child.ParentNode
}
func main() {
x := ParentType()
fmt.Println(x.Ident)
}
Would this print out "node" and also return the child struct wrapped in the parent struct with all the information, such that we can manipulate the apparent parent struct while having the actual child struct? The idea for this is similar to Java where you can return an apparent type of List but return an actual type of LinkedList.
If not, what would be the best way to achieve this functionality? Essentially I want to upcast the Child struct to a parent struct but manipulate it as if it was a child struct. Is there a way of solving this using an interface?
How is it possible to get rid of error "x.Ident undefined (type ParentNode has no field or method Ident)" at line fmt.Println(x.Ident)