I want to be able to compare the type of an object using reflect
. Here is my code:
package main
import (
"fmt"
"reflect"
)
func main() {
tst := "cat"
if reflect.TypeOf(tst) == string {
fmt.Println("It's a string!")
}
}
This gives me an error type string is not an expression
. How can I fix this only using reflect? (no type switches, etc.)
Aucun commentaire:
Enregistrer un commentaire