2012-10-21 66 views
2

我已經定義了一個名爲ti的函數,但是編譯後會顯示棄用警告。我在Eclipse中做了同樣的事情。代碼工作正常,但它顯示一個警告。scala中的棄用警告

scala> def ti(chars:List[Char],a:List[(Char,Integer)]):List[(Char,Integer)] = { 
    | if(chars.length!=0) { 
    |  var j = 1 
    |  var c = chars.head 
    |  for(i<-chars.tail) { 
    |  if(c==i) j=j+1 
    |  } 
    |  a::List((c,j)) 
    |  ti(chars.tail,a) 
    | } 
    | else a 
    | } 

警告:有3個廢棄警告;與-deprecation的細節重新運行 鈦(字符:列表[字符]答:列表[(字符,整數)])列表[(字符,整數)

,這是什麼原因?

回答

7

如果它告訴你-deprecation重新運行,你應該做的:

[email protected]:~$ scala -deprecation 
Welcome to Scala version 2.9.1 (OpenJDK 64-Bit Server VM, Java 1.6.0_24). 
Type in expressions to have them evaluated. 
Type :help for more information. 

scala> def ti(chars:List[Char],a:List[(Char,Integer)]):List[(Char,Integer)]= 
    |   { if(chars.length!=0) 
    |   { 
    |   var j=1 
    |   var c=chars.head 
    |   for(i<-chars.tail) 
    |   { 
    |   if(c==i) j=j+1 
    |   } 
    |   a::List((c,j)) 
    |   ti(chars.tail,a) 
    |   } 
    |   else a 
    |   } 

然後你得到你的警告:

<console>:7: warning: type Integer is deprecated: use java.lang.Integer instead 
     def ti(chars:List[Char],a:List[(Char,Integer)]):List[(Char,Integer)]= 
           ^
<console>:7: warning: type Integer is deprecated: use java.lang.Integer instead 
     def ti(chars:List[Char],a:List[(Char,Integer)]):List[(Char,Integer)]= 
                ^
<console>:16: warning: type Integer is deprecated: use java.lang.Integer instead 
        a::List((c,j)) 
       ^

這裏的問題是,你應該使用java.lang.Integer或者如果您不需要與Java的互操作性,只需要Int。所以你要麼import java.lang.Integer要麼更改IntegerInt