1
Scala에서 question/answer을 type erasure
으로 읽은 후에이 코드를 시도했습니다. Scala 컴파일러는 type erasure
경고를 출력하지 않았습니다.형식 지움 경고가 발생하지 않는 이유
scala> val x: List[Int] = List(1,2,3)
x: List[Int] = List(1, 2, 3)
scala> x match {
| case List(x: Int) => println("a")
| case _ => println("false")
| }
false
이 코드와 같은 경고하지 위의 코드를 출력 않는 이유 :
scala> List(1,2,3) match {
| case l: List[String] => println("list of strings")
| case _ => println("ok")
| }
<console>:9: warning: fruitless type test: a value of type List[Int] cannot
also be a List[String] (but still might match its erasure)
case l: List[String] => println("list of strings")
^
list of strings