I have this Go code:
type Op interface{}
type Op1 struct{}
type Op2 struct{}
I'm trying to map Type
s to int
. Something like this (pseudo-code):
mapping := map[reflect.Type]int
mapping[Op1] = 20
mapping[Op2] = 30
I know this is possible by creating an instance of Op1
/Op2
and call reflect.TypeOf
:
op1 := Op1{}
op2 := Op1{}
mapping := map[reflect.Type]int
mapping[reflect.TypeOf(op1)] = 20
mapping[reflect.TypeOf(op2) = 30
but my question is if it's possible to do that "statically" without creating an object. Something like .class
in Java.
Aucun commentaire:
Enregistrer un commentaire