I would like to be able to perform the following code:
abstract class A[T <: AnyRef]{
def whichClass: Class[_] = classOf[T]
}
case class X()
object B extends A[X]
object Main{
def main(args: Array[String]){
B.whichClass //should return classOf[X]
}
}
Clearly, it doesn't work in this form, since classOf[T] can be only assignged to class, not type. A got an error:
error: class type required but T found
def whichClass: Class[_] = classOf[T]
Any idea how solve this problem in another way?