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

Ulf Zibis Ulf.Zibis at gmx.de
Thu Oct 13 04:53:19 PDT 2011


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.


Am 12.10.2011 03:24, schrieb joe.darcy at oracle.com:
> 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

> 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