This is not possible in java. the only possible solution is a new challenge in the super constructor.
if the foo object can be shared between instances, you can declare it as static
public class Bar extends AbstractBar{ private static final Foo foo = new Foo(bar); public Bar(){ super(foo); } }
if the superclass is under your control, you can reorganize it and use the template method template to pull the object into the constructor instead of calling it from the subclass. this applies the hollywod principle: do not call us, we will call you;)
public abstract class AbstractBar{ private Object thing; public AbstractBar(){ this.thing = this.createThatThing(); } protected abstract Object createThatThing(); } public class Bar extends AbstractBar {
source share