Below is a work around to this restriction.
The work around is to pass a temporary holder object to the super class constructor. Then after the super class constructor has done its work, give the temporary holder object a reference to this.
The parameter delta can be used to show the principal shortcoming of this workaround - what if the superclass constructor needs to use the parameter.
import java . lang . reflect . * ;
import java . util . * ;
class Father
{
public static void main ( String [ ] args )
{
( new Son ( args . length > 0 ) ) . run ( ) ;
}
Father ( Runnable runnable , boolean delta )
{
super ( ) ;
if ( delta )
{
runnable . run ( ) ;
}
}
}
class Son extends Father implements Runnable
{
private static Map < Thread , TempRunnable > temps = new HashMap < Thread , TempRunnable > ( ) ;
private static class TempRunnable implements Runnable
{
private Son son ;
TempRunnable ( )
{
super ( ) ;
temps . put ( Thread . currentThread ( ) , this ) ;
}
public void run ( )
{
son . run ( ) ;
}
}
Son ( boolean delta )
{
// super ( this ) ; // the dream
super ( new TempRunnable ( ) , delta ) ;
temps . get ( Thread . currentThread ( ) ) . son = this ;
}
public void run ( )
{
System . out . println ( "Hello World" ) ;
}
}