package main import ( "fmt" "reflect" ) func main() { var x *int fmt.Println(reflect.ValueOf(x).IsNil()) // true }
package main import ( "fmt" "reflect" ) type Person struct { Name string Age int } func main() { var x interface{} fmt.Println(reflect.ValueOf(x).IsNil()) // true x = Person{Name: "Alice", Age: 30} fmt.Println(reflect.ValueOf(x).IsNil()) // false }In this example, we declare an empty interface variable `x`, which initially has a nil underlying value. We use `reflect.ValueOf()` to get the reflect value of `x`, and call `IsNil()` to check if it is nil (which it is). We then assign a non-nil value to `x`, and again call `IsNil()`. This time the output will be false, indicating that `x` now has a non-nil underlying value. The package library for `reflect` is the standard library `reflect` package in Go.