As is shown by the following code: n := localplugin.NewPluginNet()
, the type of n
is localnet.Net
, which is a interface implemented by the struct pointer *localnet.DomainSocket
. Function func NewPluginNet() localnet.Net
returns a nil pointer to n
.
var n localnet.Net
n = localplugin.NewPluginNet()
fmt.Println("----> ", n)
if n == nil {
fmt.Println("n is nil")
}else{
fmt.Println("n is not nil : ", n)
}
fmt.Println(reflect.TypeOf(n), reflect.TypeOf(nil), n)
The following is the output of the code above.
----> <nil>
n is not nil : <nil>
*localnet.DomainSocket <nil> <nil>
Why does n is not nil ?
===================================
var n1 *localnet.DomainSocket
n1 = nil
fmt.Println(">> ", n1)
if n1 == nil {
fmt.Println(">>n1 is nil")
}else{
fmt.Println(">>n1 is not nil : ", n)
}
fmt.Println(reflect.TypeOf(n1), reflect.TypeOf(nil), n1)
However, it's correct for this case:
>> <nil>
>>n1 is nil
*localnet.DomainSocket <nil> <nil>