Why does this() and super() have to be the first statement in a constructor?

Mike Duigou mike.duigou at oracle.com
Tue Oct 11 13:03:49 PDT 2011


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)

The request also resulted in the identification of several older requests:

http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4093999
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4879515
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4107474

The first issue (4093999) points out that the JVMS specification only requires that super() or this() be called before instance members (including "this") are accessed. The restriction that super() or this() must be the first statement of a constructor is a tighter restriction imposed by the Java language. 

The proposal was ultimately not selected for project coin:

http://mail.openjdk.java.net/pipermail/coin-dev/2009-March/000817.html

Note that the resolution in leaves open the opportunity (*not* commitment) for it to be addressed in future coin efforts or at any time by an enterprising compiler hacker. 

I do still think the restriction is an annoyance :-)

Mike




More information about the coin-dev mailing list