Why not set the value directly

I read the source of the project and found the code there:

private var _responded: Boolean = _ { _responded = false } 

I don’t understand why he wrote it like this, right:

 private var _responded = false 

What is the difference between the two?

+7
source share
2 answers

I am the author of this code.

Write this:

 private var _responded = false 

causes this warning when compiling (with older versions of Scala, it seems not to be a problem with Scala 2.9):

 the initialization is no longer be executed before the superclass is called 

You can report this alert to find more information.

+7
source

I'm going to take a chance here, but it is very similar to the code created using intellij automatic Java to convert Scala.

This converter tries to support the semantics of the original Java as close as possible and therefore tends to create very non-idiomatic code, as well as many nested areas and mutable variables.

+6
source

All Articles