The program successfully prints the 3,1,2 but I am curious about why it says that this expression is unused?
3,1,2
package Collection object basics { def main(args: Array[String]): Unit = { var res = List[Int](1, 2) res.::=(3) // Unused expression without side effects println(res.mkString(",")) } }
Perhaps some IntelliJ bug, that thinks it's just :: - pre-pend method invocation without assignment result to var. Next construction with post-fix annotation works for me well: res ::= 3
::
var
res ::= 3
2.1m questions
2.1m answers
60 comments
57.0k users