|
[#17] |
project: compiler |
priority: medium |
category: bug |
|
submitter |
assigned to |
status |
date submitted |
|
Stephane |
Nikolay |
fixed |
2003-06-26 11:52:54.0 |
subject |
initialization of class parameters |
code |
class Quantity {
def getValue = 0;
def connect(c: Constraint) = c.newValue;
}
abstract class Constraint(q: Quantity) {
def newValue: Unit;
q connect this
}
class Adder(q: Quantity) extends Constraint(q) {
def newValue = System.out.println(q.getValue);
}
object Main {
def main(args: Array[String]): Unit = {
val x = new Quantity;
new Adder(x);
()
}
}
|
what happened |
Exception in thread "main" java.lang.NullPointerException
at Adder$class.newValue(src/Main.scala)
|
what expected |
value 0 should be printed out !
Michel
the problem is that the super-constructor is called before the fields of the class are initialized. I think addconstructors should be modified in order to place the call to the superconstructor just after all assignments to local fields
|
[back to overview] |