【发布时间】:2017-10-07 14:03:42
【问题描述】:
我设置了一个 Scala 项目并从 http://www.scalatest.org/ 添加了这个 sn-p
import collection.mutable.Stack
import org.scalatest._
class ExampleSpec extends FlatSpec with Matchers {
"A Stack" should "pop values in last-in-first-out order" in {
val stack = new Stack[Int]
stack.push(1)
stack.push(2)
stack.pop() should be (2)
stack.pop() should be (1)
}
it should "throw NoSuchElementException if an empty stack is popped" in {
val emptyStack = new Stack[Int]
a [NoSuchElementException] should be thrownBy {
emptyStack.pop()
}
}
}
并且 IntelliJ (IDEA 2017.1.2) 向我显示使用 new Stack[Int] 的警告:
搜索警告向我显示了这个问题: https://issues.scala-lang.org/browse/SI-9068
但我仍然有这些问题:
我得到一个弹出窗口,它分为两个区域。这是否意味着有两个警告,每个警告有 2 行。什么是真实信息?对于第二个区域,我看到 必须添加前缀 和 正在建设中。
为什么我没有看到正确的弃用警告,就像在此处添加的一样:https://github.com/scala/scala/pull/5260/files#diff-1ab096eae7e5571b6410a123567aac0aR57
在 github/API 文档上他们说:
Use a List assigned to a var instead但我不能只用List替换Stack,因为.push()不适用于该类。还是我应该完全切换到 List API?使用var或val分配列表有什么区别? 例如,我不能通过list.add(2)添加项目,即使它是用val分配的吗?
我通过 Homebrew 安装了 Scala 2.12.2。我不确定我是否是 IntelliJ,它使用的是自己的版本,因为我也需要通过 IntelliJ 下载它,但无论如何它是相同的版本,所以我的设置如下所示:
顺便说一句:在终端 / Scala REPL 我得到这个输出
scala> val stack = new Stack[Int]
<console>:14: warning: class Stack in package mutable is deprecated (since 2.12.0): Stack is an inelegant and potentially poorly-performing wrapper around List. Use a List assigned to a var instead.
val stack = new Stack[Int]
^
因此,适当的弃用警告似乎在那里起作用。
【问题讨论】:
标签: scala intellij-idea