【问题标题】::import command inside Scala REPLScala REPL 中的 :import 命令
【发布时间】:2013-09-26 06:49:26
【问题描述】:

Scala in Action一书中说,在 Scala REPL 中使用 :import 命令我们会看到:

scala> :imports 
    1) import java.lang._       (153 types, 158 terms)
    2) import scala._           (798 types, 806 terms)
    3) import scala.Predef._    (16 types, 167 terms, 96 are implicit)

根据这本书,上面的那些包都是自动导入的。但在我的 REPL (Scala 2.10.2) 中它只返回一行:

scala> :imports
     1) import scala.Predef._   (162 terms, 78 are implicit)

有什么问题吗?

【问题讨论】:

  • 书中使用了哪个版本的Scala?

标签: scala


【解决方案1】:

“Scala in Action”是为 2.9 编写的:

:~$ scala
Welcome to Scala version 2.9.2 (Java HotSpot(TM) 64-Bit Server VM, Java 1.7.0_25).
Type in expressions to have them evaluated.
Type :help for more information.

scala> :imports
 1) import java.lang._             (193 types, 199 terms)
 2) import scala._                 (798 types, 804 terms)
 3) import scala.Predef._          (16 types, 167 terms, 96 are implicit)

【讨论】:

  • 感谢阿拉塔。但在我得到的电子书中,它是 2.10.0。作者:“我运行的是 Scala 版本 2.10.0,所有代码示例都应该适用于这个版本及以上版本。”
  • @Pauli 我认为这个答案是正确的,因为在手册页上写着这本书是为 2.10 更新的,但起初它是在 2.9 下编写的。并且 repl 列表没有为 2.10 更新。因为这个输出实际上只在 2.9
猜你喜欢
  • 2018-10-19
  • 2019-03-01
  • 2012-04-10
  • 1970-01-01
  • 2015-04-20
  • 2018-09-22
  • 2013-08-04
  • 1970-01-01
  • 2012-02-15
相关资源
最近更新 更多