2013-12-22 1 views
1

Scala에서 question/answertype 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 

답변

3

첫 번째 사건은 단지 테스트되지 않은 유형 -이 패턴 일치에 의한 테스트의 목록이 정확히 하나 가지고 정수 요소.

관련 문제