reflect.IsNil() Function in Golang with Examples
Go language provides inbuilt support implementation of run-time reflection and allowing a program to manipulate objects with arbitrary types with the help of reflect package. The reflect.IsNil() Function in Golang is used to check whether its argument v is nil. The argument must be a chan, func, interface, map, pointer, or slice value; if it is not, IsNil panics.
Note: IsNil is not always equivalent to a regular comparison with nil in Go. For example, if v was created by calling ValueOf with an uninitialized interface variable i, i==nil will be true but v.IsNil will panic as v will be the zero Value.
Syntax:func (v Value) IsNil() bool
Parameters: This function does not accept any parameter.
Return Value: This function returns whether its argument v is nil or not.
Below examples illustrate the use of above method in Golang:
main(): body == nil ? true