This is a creation in Article, where the information may have evolved or changed.
To determine whether a value is nil, it is best to compare it directly with nil, rather than pass the parameter of interface{} to another function to judge.
But using reflection can be interface{} to determine nil, such as TESTNIL5.
See the example code below, A is a null pointer, but only TESTNIL4 and TESTNIL5 can be correctly judged:
typeStatestruct{}funcTestnil1 (A, BInterface{})BOOL{returnA = = b}funcTestnil2 (a *state, bInterface{})BOOL{returnA = = b}funcTestnil3 (AInterface{})BOOL{returnA = =Nil}funcTestnil4 (a *state)BOOL{returnA = =Nil}funcTESTNIL5 (AInterface{})BOOL{V: = reflect. ValueOf (a)return!v.isvalid () | | V.isnil ()}funcMain () {varA *state fmt. Println (a) fmt. Println (Testnil1 (A,Nil) FMT. Println (Testnil2 (A,Nil) FMT. Println (Testnil3 (a)) fmt. Println (Testnil4 (a)) fmt. Println (TESTNIL5 (a))}
The output is:
<nil>
False
False
False
True
True