【发布时间】:2015-10-17 04:27:50
【问题描述】:
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
}
类型类型不匹配;成立 : List[(Any, Class[_ >: Int with NullPointerException with Thread with String])] 必需:List[(AnyRef, Class[_])]
If dataSet4 is removed from List, the compile time error disappears
请提出建议,Class[_] 有什么问题。是不是 相当于 java 中的 Class[?] ?我很感激,如果你也建议 这样做的正确声明..
【问题讨论】:
标签: list scala generics collections