I've never quite figured this one out. See
https://issues.scala-lang.org/browse/SI-4437 including the fact that
martin had a chance to endorse changing it; but that's a little
indirect to serve as an edict. I feel like if there were no objection
I'd have fixed this a long long time ago, but I can't remember.
On Wed, Apr 25, 2012 at 9:12 AM, martin odersky <martin....@epfl.ch> wrote:This seems like a distinction without a difference. We know what
> It corresponds to the JVM. You can omit a field initialization but not a
> local variable initialization. Omitting local variable initializations means
> that the compiler has to be able to synthesize a default value for every
> type. That's not so easy in the face of type parameters, specialization, and
> so on.
happens if a field definition is omitted. We can do the same thing
for locals, even if it requires an instruction or something.
The JVM will initialize object fields by default and require that local variables are initialized explicitly.
The JVM will initialize object fields by default and require that local variables are initialized explicitly.
I was always thinking that with a declaration of a local variable
var x: T = _
that variable IS actually initialized explicitly, and it could also implemented that way for locals without violating the JVM constraints and without having to implement definite assignment.
If I read the Scala-Spec correctly it only specifies that a variable with a _-initialization has a default initial value. It does not specify whether this initial value is given by the JVM or set with an explicit byte-code instruction.
_:T