Why does this() and super() have to be the first statement in a constructor?
Ulf Zibis
Ulf.Zibis at gmx.de
Thu Oct 13 06:50:47 PDT 2011
Am 13.10.2011 15:16, schrieb Henri Gerrits:
> Ulf,
>
> In rule 1, using a field access as the left-hand operand in a simple (not compound, of course) assignment could be allowed before an explicit call to this() or super().
May be, but should be waived to future, to simplify the 1st loosening step.
Workaround: First assign to temporal local variable, and after this/super() to instance field.
Hotspot would anyway optimize this.
> In rule 2, by "1." I assume you mean "first"?
Correct! "1." is german notation for "1st". ;-)
-Ulf
>
> Regards,
>
> Henri
>
> ----- Original Message -----
>> From: Ulf Zibis<Ulf.Zibis at gmx.de>
>> To: joe.darcy at oracle.com
>> Cc: coin-dev at openjdk.java.net; Mike Duigou<mike.duigou at oracle.com>
>> Sent: Thursday, October 13, 2011 7:53 AM
>> Subject: Re: Why does this() and super() have to be the first statement in a constructor?
>>
>> Joe,
>>
>> now I'm a little bit confused.
>>
>> First you refer simply:
>> "The answer to the question has already been given on the list. ..."
>> Now you point to Bug 4093999 with IMHO very sophisticated loosening cases, e.g.:
>> obj.super().
>>
>> I think, as first step, this request could be handled like as on switch
>> enhancements (only for
>> String, but not for all objects or arbitrary expressions).
>>
>> Following loosening rules seem simple, clear and enough to me:
>> 1. Allow the explicit call to super() or this() only before any reference to
>> this or instance fields
>> or methods.
>> 2. In case where no explicit call to super/this() is given, add implicit call to
>> the no params
>> super() as 1. statement.
>> 3. Allow super() or this() call only outside any block ({...}, if, for, etc.),
>> maybe except
>> synchronize block.
>> 4. Allow only one of super() or this() and only once.
>>
>> Further loosenings could be discussed later, as they need complicated data flow
>> analysis.
>>
>> I agree, that other language changes might have higher priority.
>>
>> -Ulf
>>
More information about the coin-dev
mailing list