Why does this() and super() have to be the first statement in a constructor?
joe.darcy at oracle.com
joe.darcy at oracle.com
Tue Oct 11 18:24:43 PDT 2011
On 10/11/2011 1:56 PM, Ulf Zibis wrote:
> Am 11.10.2011 22:03, schrieb Mike Duigou:
>
>> I submitted a proposal for exactly this request as part of the original coin call for proposals.
>>
>> http://mail.openjdk.java.net/pipermail/coin-dev/2009-March/000798.html
>>
>> (long thread follows)
>>
>
> Much thanks Mike!
>
> Unfortunately I missed this, as I inscribed to coin list on March 30 2009.
>
> Most work for defining a standard seems to be done already.
>
No.
As pointed out in the thread cited by Mike, there were technical issues
discussed in various related bugs, in particular
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4093999
and from feedback from Jeremy Manson on the thread:
> Here are a couple of constructors for class Foo that should probably
> result
> in compilation errors:
>
> Foo() {
> if (something) {
> super(blah)
> }
> }
> Foo() {
> super(blah);
> super(blah);
> }
>
> Also, it seems to me that you would want to be careful about access to
> fields of the parent object before the invocation of super().
http://mail.openjdk.java.net/pipermail/coin-dev/2009-March/000805.html
> So my answer to the initial question now is:
>
> This restriction is a historical convenience to make the implementation of the java compiler less
> complicated, simplify the java language spec, and perhaps to avoid the additional discussion in
> "Learning Java" books ;-) , but there is no technical reasonable for this.
>
>
>
Until and unless data flow analysis akin to definite
assignment/unassignment is defined to permit the sort of desirable
programs the proposal wants to allow, the main piece of technical work
needed to implement this request has not been done.
IMO this loosening would be fine in and of itself, but it has too high
an opportunity cost compared to other language changes that could be
done with the same amount of effort.
-Joe
More information about the coin-dev
mailing list