2

나는 package 객체에이 방법을 가지고 : 컴파일러 (I 버전 2.9.2이가) type T is unused or used in non-specializable positions.을 말한다 이유스칼라 컴파일러에서 왜이 유형이 특수화 할 수없는 위치에 사용된다고 말합니까?

def extractLoop[@specialized T](x: Map[T, T]) = { 
    val whatever = x.head 
    val stop = whatever._1 
    def iteration(
      acc: Seq[T] = Seq(whatever._1, whatever._2), 
      last: T = whatever._2): Seq[T] = { 
     val next = x(last) 
     if (next == stop) acc 
     else iteration(acc :+ next, next) 
    } 
    iteration() 
} 

하지만 아직 이해할 수 없다?

답변

5

저는 이유가 단순히 당신이 전문이 아닌 Map[T, T]을 사용하고 있다고 믿습니다.

일부 그림 :

scala> class MyMap[A,B] 
defined class MyMap 
scala> def extractLoop[@specialized T](x: MyMap[T, T]) = { 
    | sys.error("TODO") 
    | } 
<console>:8: warning: type T is unused or used in non-specializable positions. 
     def extractLoop[@specialized T](x: MyMap[T, T]) = { 
     ^
extractLoop: [T](x: MyMap[T,T])Nothing 

하지만이 두 가지 유형의 매개 변수에 대한 MyMap을 전문으로하는 경우, 당신은 경고 없다 :

scala> class MyMap[@specialized A,@specialized B] 
defined class MyMap 
scala> def extractLoop[@specialized T](x: MyMap[T, T]) = { 
    | sys.error("TODO") 
    | } 
extractLoop: [T](x: MyMap[T,T])Nothing 
+0

이 흠, 내가 이것을 이해 한 것입니다. –

관련 문제