I was looking at the scala reflection overview and I'm wondering if it is possible to use a java.lang.Class<T>
as a Type in Scala 2.10.
import scala.reflect.runtime.{ universe => ru }
class Reflector {
def getType: ru.Type = {
ru.typeOf[java.lang.String]
}
def getType[T](clazz: Class[T]): ru.Type = {
//is it possible to implement me?
}
}
Is it possible to implement the parse[T](clazz: Class[T]): ru.Type
method without changing its signature in order to be able to call it from java with new Reflector().parse(String.class)
?
You could implement your method like this:
And then call it like this:
You might be interested in the smirror library as it contains a similar method
Where
SClass
contains atyp
property.Edit
You might want to change the method to this (that would keep the same signature)