こんなふうにコンストラクタで引数を要求する親クラスがあって、
public class Thing { public Thing(int i) { ・・ } }
子クラス内では、どっかのメソッドから値を取ってきて親クラスのコンストラクタに渡し、かつ子クラスでもその値を保持したい場合、super はコンストラクタ中で最初に呼び出す必要があるので、
public class MyThing extends Thing { private final int arg; public MyThing() { super(arg = SomeOtherClass.func()); } }
のようにしたいが、これはできない。
そんな時は、以下のようにする。
public class MyThing extends Thing { private final int arg; public MyThing() { this(SomeOtherClass.func()); } private MyThing(int i) { super(i); arg = i; } }