p := &Person{Attr:&Attribute{}}
if p.Attr != nil && p.Attr.Age < 10 {
fmt.Println("Too Young")
}
func NewPerson() &Person {
return &Person{Attr:&Attribute{}}
}
Expose properties as methods and do the check in the method can make the caller use easier.
--
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...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Hello,Have been struggling with mitigating against nil pointer deference and i would appreciate if anyone can helpCode 1: Works fileCode 2: Error