val list = getValueAndItsType()
list.foreach{ e =>
val data = e._1
val dataType = e._2
println( dataType.isAssignableFrom( value.getClass ) )
}
def getValueAndItsType() : List[ (AnyRef, Class[_]) ] = {
val dataSet1 = ("some string data", classOf[String])
val dataSet2 = (new Thread(), classOf[Thread])
val dataSet3 = (new NullPointerException(), classOf[NullPointerException])
val dataSet4 = (5, classOf[Int])
val list = List(dataSet1, dataSet2, dataSet3, dataSet4)
list
}
关于stackoverflow的另一个问题。现在,我得到了编译时错误: -
value isAssignableFrom is not a member of Any
在println( dataType.isAssignableFrom( value.getClass ) )
答案 0 :(得分:0)
List[ (Any, Class[_]) ]
工作。