【问题标题】:value isAssignableFrom is not a member of Any in scala值 isAssignableFrom 不是 scala 中 Any 的成员
【发布时间】:2015-07-27 15:44:53
【问题描述】:
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 ) )

【问题讨论】:

    标签: scala object types


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2022-10-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-11-28
      相关资源
      最近更新 更多