Can a java subclass's private final field be initialized before the super constructor completes?

前端 未结 3 1773
感动是毒
感动是毒 2021-01-23 03:58

I have a pair of classes looking like this;

public abstract class Class1 {

//...

    public Class1() {
        //...
        function2();
        //...
    }

         


        
3条回答
  •  离开以前
    2021-01-23 04:54

    Your design is an instance of the "leaked this problem" and is an anti-pattern in Java. You should never call out to a publicly overridable method from a constructor.

提交回复
热议问题