I need to check if an interface value is `nil.
But by using reflection it is giving me an error:
reflect: call of reflect.Value.Bool on struct Value.
Through nil
it is not giving an error for nil
value.
I need to check if an interface value is `nil.
But by using reflection it is giving me an error:
reflect: call of reflect.Value.Bool on struct Value.
Through nil
it is not giving an error for nil
value.
There are two things: If y is the nil interface itself (in which case y==nil will be true), or if y is a non-nil interface but underlying value is a nil value (in which case y==nil will be false).
Here's an example.