What's wrong with overridable method calls in constructors?

后端 未结 7 1898
谎友^
谎友^ 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:11

    I guess for Wicket it's better to call add method in the onInitialize() (see components lifecycle) :

    public abstract class BasicPage extends WebPage {
    
        public BasicPage() {
        }
    
        @Override
        public void onInitialize() {
            add(new Label("title", getTitle()));
        }
    
        protected abstract String getTitle();
    }
    

提交回复
热议问题