-
Enhancement
-
Resolution: Not an Issue
-
P4
-
None
-
1.1.4, 1.1.5, 1.4.1, 1.4.2, 5.0, 7
-
x86, sparc
-
solaris_2.5.1, windows_nt, windows_xp, windows_7
Name: rm29839 Date: 11/19/97
The restriction that a call to a superclass constructor can only be placed as the first statement of a constructor serves
no purpose and should be relaxed; i.e., it should be possible to invoke a superclass constructor anywhere in a constructor,
as long as it's guaranteed that exactly one such call is executed. I believe this could be verified using the same flow analysis t
hat is already applied to verify the initialization of blank finals. Obviously, references to instance variables or instance
methods would be disallowed until after the superclass constructor has returned.
The current constraint distorts the implementation of some classes by encouraging programmers to place complex
expressions into the argument list of a call to super(). Here's a not-atypical local example:
super(c,HashtableUtil.
makeHashtable(
new Object[] {"jobNumber","fundId","detailedFundId"},
new Object[] {job.jobNumber(),
detailedFund.fund().id(),
detailedFund.id()}));
The above also applies to calls to forms of this(), of course.
(Review ID: 20079)
======================================================================
The restriction that a call to a superclass constructor can only be placed as the first statement of a constructor serves
no purpose and should be relaxed; i.e., it should be possible to invoke a superclass constructor anywhere in a constructor,
as long as it's guaranteed that exactly one such call is executed. I believe this could be verified using the same flow analysis t
hat is already applied to verify the initialization of blank finals. Obviously, references to instance variables or instance
methods would be disallowed until after the superclass constructor has returned.
The current constraint distorts the implementation of some classes by encouraging programmers to place complex
expressions into the argument list of a call to super(). Here's a not-atypical local example:
super(c,HashtableUtil.
makeHashtable(
new Object[] {"jobNumber","fundId","detailedFundId"},
new Object[] {job.jobNumber(),
detailedFund.fund().id(),
detailedFund.id()}));
The above also applies to calls to forms of this(), of course.
(Review ID: 20079)
======================================================================
- duplicates
-
JDK-4107474 Superclass Constructors Must be First
- Closed
-
JDK-7126297 Remove requirement for super() and this() to be 1st call in constructors
- Closed
- relates to
-
JDK-4914488 Assert keyword position in constructors
- Closed
-
JDK-8159747 4.10.1.9: Clarify that putfield can early-assign to fields of 'this'
- Closed