vendredi 14 octobre 2022

why reflect.TypeOf(new(Encoder)).Elem() != reflect.TypeOf(interfaceVariable)?

Here's the short test:

type Encoder interface {
    Encode()
}
func main() {
    encoderInterface1 := reflect.TypeOf(new(Encoder)).Elem()
    var en Encoder
    encoderInterface2 := reflect.TypeOf(en)
    fmt.Println(encoderInterface1 == encoderInterface2)
}

Outputs false.

Why is it false? I was expecting it to be true.





Aucun commentaire:

Enregistrer un commentaire