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类的,不知道哪里出错了,书的示例代码照样编译出错。

百度搜索未果,FQgoogle好不容易才发现结果,最后发现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继续搞。

posted @ 2015-10-28 18:42  wmx3ng  阅读(3744)  评论(0编辑  收藏  举报