samedi 10 septembre 2016

A => Class[A] using ClassTag?

Looking at ClassTag#runtimeClass, it has a return type of Class[_], i.e. a Class with, as I understand, a wildcard parameter.

I tried to implement a method: A => ClassTag[A]:

import scala.reflect._

scala> def f[A](x: A)(implicit ev: ClassTag[A]) = ev.runtimeClass
f: [A](x: A)(implicit ev: scala.reflect.ClassTag[A])Class[_]

But, the output of the def's definition is, as the docs show, Class[_].

Is it possible to change f such that its return type is Class[A]? If not, then why is it not possible?





Aucun commentaire:

Enregistrer un commentaire