2
import scala.reflect.runtime.universe._
import scala.reflect.ClassTag
class A
class B
def foo[A](x: A) = typeOf[A] match {
case x:A => println("this an A")
case _ => println("no match")
}
}
但是這將被證明無用的不匹配是可能的,我得到:功能採取任何對象作爲參數
fruitless type test: a value of type runtime.universe.Type cannot also be a A
我想有foo
採取類的任何type
,從基本類型定製類。我會怎麼做?
case x:Int => println(「this an Int」)你不覺得你跟着這個 –
a typeOf [A]不是A –