I’m using the golang pointer to do some empty check. But I’m so confused about how to check the nil situation. It’s much different from C. For example there is a mock object
type Node struct {
Val int
Next *Node
}
When I create object
a := &Node{Val:1,Next:nil}
And I want to judge if the a’s next value is empty. I use the following code
if *a.Next == nil{}
But the complier raise error that the type is not align. Does it not mean the object (referred by a point)’s Next property? After I wrapped the *a with () it works. So I don’t know why the * operator is not work.
Another question is that when I use the following
if a.Next == nil {}
It also works fine. But it is strange. Since a should refer to a memory address value which contains object. Memory address can’t have “Next” property, only object has it. So why the a.Next can get the value instead of raising exception?
feel confused.