I have code which extracts values from a Map, which I have aliased as:

type CsvRow = Map[String, Any]

and extraction class:

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

The compiler gives me this warning:

[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]               ^

But shouldn't the ClassTag and TypeTag ensure that that type information exists?

1

There are 1 answers

0
LynxZh On

This is due to you are putting this into the generalization class definition. Try to change to following:

case Some(v: T) => v