3 ms·
Works just fine if you change: this.test(7); test(10); to test(10); this.test(7); Of course, since this is a made-up example to highlight on
by jdbernard 10y ago
Works just fine if you change:
this.test(7);
test(10);
to
test(10);
this.test(7);
Of course, since this is a made-up example to highlight one of your pet problems I don't know if that ordering is important to you. However there is a reason for the insistence on calls to the constructor being first, and it's not specific to Java. You run into this problem any time you have code that might mutate a data structure before if has been initialized. There are other ways to write this kind of code that avoids this, but it is by no means unusual in imperative code.