I setup a Scala project and add this snippet from http://www.scalatest.org/
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()
}
}
}
and IntelliJ (IDEA 2017.1.2) is showing me a warning for the usage of new Stack[Int]
:
Searching for the warning showed me this issue: https://issues.scala-lang.org/browse/SI-9068
But I still have these questions:
I get a popup which is splitted into two areas. Does it mean that there are two warnings, each with 2 lines. What is the real information? For the second area I see Reference must be prefixed and Under construction.
Why I don't see the proper deprecated warning, like it was added here: https://github.com/scala/scala/pull/5260/files#diff-1ab096eae7e5571b6410a123567aac0aR57
On github/API docs they sai:
Use a List assigned to a var instead
But I can't just replaceStack
withList
, because.push()
is not available for that class. Or should I switch to the List API completely? And what's the difference between assigning the list withvar
orval
? Can't I add items for instance vialist.add(2)
even if it was assigned withval
?
I installed Scala 2.12.2 via Homebrew. I'm not sure if I'm IntelliJ it is using its own version, because I needed to download it via IntelliJ as well, but anyway it's the same version, so me setup looks like this:
BTW: in the terminal / Scala REPL I get this output
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]
^
So the proper deprecation warning seems to work there.