What's wrong with overridable method calls in constructors?

后端 未结 7 1908
谎友^
谎友^ 2020-11-21 04:53

I have a Wicket page class that sets the page title depending on the result of an abstract method.

public abstract class BasicPage extends WebPage {

    pub         


        
7条回答
  •  傲寒
    傲寒 (楼主)
    2020-11-21 05:08

    If you call methods in your constructor that subclasses override, it means you are less likely to be referencing variables that don’t exist yet if you divide your initialization logically between the constructor and the method.

    Have a look on this sample link http://www.javapractices.com/topic/TopicAction.do?Id=215

提交回复
热议问题