scala 2.11報錯error: not found: type Application


FROM: http://j-q-j.org/scala/scala-2-11-application-error.html

這兩天學習scala,官網下載的最新版本2.11,書用的是《Programming in scala》,看到類和對象,這一章最后一段代碼

1
2
3
4
5
import ChecksumAccumulator.calculate
object FallWinterSpringSummer extends Application {
  for (season <- List("fall", "winter", "spring"))
     println( season + ": " calculate(season))
}

scalac FallWinterSpringSummer.scala報錯如下

1
error: not found: type Application

查找scala官方api,發現內置了Application類的,不知道哪里出錯了,書的示例代碼照樣編譯出錯。

百度搜索未果,翻牆google好不容易才發現結果,最后發現stackoverflow大神的解釋

http://stackoverflow.com/questions/26176509/why-does-2-11-1-fail-with-error-not-found-type-application

Application has been deprecated from scala 2.9, probably it has been deleted in scala 2.11 (it still exists in scala 2.10) even though at the moment I can't find proofs for that, use App instead.

Proof found, this is the scala 2.11 branch on github which has only an App.scala and this is the 2.10which has App.scala and Application.scala with a deprecated warning.

scala 2.9以后的版本廢棄了Application而是啟用了App類,修正后代碼如下

1
2
3
4
5
import ChecksumAccumulator.calculate
object FallWinterSpringSummer extends App {
  for (season <- List("fall", "winter", "spring"))
     println( season + ": " calculate(season))
}

還是不要趕時髦的好,乖乖下載個2.9繼續搞。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM