How to call in the abstract class the constructor of the class that specifically inherits it? Type of such:
public abstract class AbstractClass { public Abstract foo() { //Когда метод foo вызовется наследником AbstractClass a = new this(); //здесь надо вызвать конструктор наследника a.bar(); //как-то меняем состояние, вызывая метод наследника return a; //и возвращаем экземпляр наследника } public abstract void bar(); } But in this example, it gives an error:
java: as it is release 8
foo()method is already an instance method? Take an instance of the heir and just call itsfoo()method. And even better,bar()right away. - andreychanew this()trygetClass().newInstance()- Chubatiy