jeudi 9 mars 2017

what is zero value of reflect.Value in golang

In golang reflect package, reflect.value.IsValid has those comments:

IsValid reports whether v represents a value. It returns false if v is the zero Value. If IsValid returns false, all other methods except String panic. Most functions and methods never return an invalid value. If one does, its documentation states the conditions explicitly.

Read above, i am very confused. i don't know what is zero value of reflect.Value and use it call isValid get false.

I write some code to test:

var haha *int
fmt.Println(reflect.ValueOf(haha).IsValid()) //true
var hehe interface{}
fmt.Println(reflect.ValueOf(hehe).IsValid() //false





Aucun commentaire:

Enregistrer un commentaire