Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
364 views
in Technique[技术] by (71.8m points)

Scala List: why the IDEA prompts that Unused expression without side effects

The program successfully prints the 3,1,2 but I am curious about why it says that this expression is unused?

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(","))
  }
}
question from:https://stackoverflow.com/questions/65882666/scala-list-why-the-idea-prompts-that-unused-expression-without-side-effects

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

enter image description here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...