When a nil of golang is passed into the method, it becomes not nil?. Why is that?

[]
the value is nil
not nil

1. Why is not nil?
2 printed in Console? How to realize that nil? can be printed out in Console (that"s why interface {} is used because of the need for a general method.)

Feb.07,2022

API interface, including two aspects

  • type interface type
  • value API dynamic value

judge that data interface {} = = nil, should satisfy both aspects.
in your example, type is valuable, value = = nil

this corresponds to reflect.TypeOf and reflect.ValueOf methods


is there any other way besides reflection?

func Console(data interface{}) {
    v := reflect.ValueOf(data)
    if(v.IsNil()){
        fmt.Println("is nil")
    }else{
        fmt.Println("not nil")
    }
}
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b3523b-2bf51.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b3523b-2bf51.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?