lundi 28 décembre 2015

Scala pattern matching on generic type with TypeTag generates a warning while ClassTag not?

I have two very similar methods. The only difference is the use of ClassTag and TypeTag:

def matchClass[A: ClassTag](v: Any) =
    v match {
        case a: A => "it's A"
        case _ => "not A"
    }

def matchType[A: TypeTag](v: Any) = ... // same code as matchClass

A compile warning will show for matchType, but not for matchClass:
abstract type pattern A is unchecked since it is eliminated by erasure case a: A

Why is there a warning? why does it show only for TypeTag and not ClassTag?





Aucun commentaire:

Enregistrer un commentaire