value isAssignableFrom不是scala中Any的成员

时间:2015-07-27 06:00:54

标签: scala object types

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 ) )

1 个答案:

答案 0 :(得分:0)

List[ (Any, Class[_]) ]工作。