fg said:
I think he is...
You can also cheat if you need a better treatment of your constructor
parameters :
public SomeClass(Object1param1, Object2param2)
{
super(doSomeWork(param1, param2));
}
private *static* Object doSomeWork(Object1param1, Object2param2)
{
if (param1.xxx() && param2.yyy()) return sth;
return sthEse;
}
I insist on the fact that the called method is static : the object is not yet
initialized, so you cannot access its fields nor its instance methods.
The compiler also insists on that, because it won't allow
a usage of "this", either explicitly or implicitly, until
the parent constructor has returned. Therefore, you cannot
reference instance members within the super() parameter
list.
There is a work-around that most beginners should avoid.
That is to override a public or protected instance method
that is known to be called from a parent constructor. That
would send control back into the child instance before its
parent has been fully constructed. It's dangerous and not
for the timid, and I use it under very controlled situations
(and with plenty of documentation).