我有从Map中提取值的代码,我将其别名为:
type CsvRow = Map[String, Any]
和提取类:
class CsvExtractor(row: CsvRow) extends Extractor {
def get[T: TypeTag: ClassTag](k: String): T = getOption[T](k).get
def getOption[T: TypeTag: ClassTag](k: String): Option[T] = {
row(k) match {
case v: Some[T] => v
case None => None
}
}
}
编译器给了我这个警告:
[warn] /Users/axue/workspace/events/schema-kontrol/src/main/scala/com/lumoslabs/schemakontrol/core/extractor/CsvExtractor.scala:12: abstract type T in type pattern Some[T] is unchecked since it is eliminated by erasure
[warn] case v: Some[T] => v
[warn] ^
但ClassTag和TypeTag不应该确保存在该类型信息吗?
答案 0 :(得分:0)
这是因为你将它放入泛化类定义中。尝试更改为以下内容:
case Some(v: T) => v