In Scala I am using reflection to examine method signatures. Some of these methods are parametrized, like in the following example:
implicit def toOption[T](x:T):Option[T] = Some(x)
When I use reflection to get a Symbol that represents toOption
, say sym
, and do
sym.typeSignature.paramLists.head.head.typeSignature
I get the type named T
(it’s the type of x
, the first argument in the first argument list). If I have some value y
, it can’t be of type T
but I can pass it into toOption
anyway because T
is actually a type parameter, not a normal type.
So my question is the following: how can I tell if a given Type is a generic type parameter (like T
in the above example) or a specific type?
Ideally I’d like to determine this at runtime, but if the information is available only at compile time I’d also like to hear how to get it then.
Aucun commentaire:
Enregistrer un commentaire