spring bean with dynamic constructor value

前端 未结 3 368
天命终不由人
天命终不由人 2020-12-05 03:26

I need to create an Object which is in-complete without the constructor argument. Something like this

Class A  {
  private final int timeOut
  public A(int t         


        
3条回答
  •  隐瞒了意图╮
    2020-12-05 03:45

    Do it explicitly:

    interface Bean {
        void setTimeout(int timeout);
    }
    

    class BeanImpl implements Bean {
        private int timeout;
    
        @Override
        public void setTimeout(int timeout) {
            this.timeout = timeout;
        }
        ...
    }
    

    
        ...
        
        ...
    
    

    class Client {
        private Bean bean;
        public void setBean(Bean bean) {
            this.bean = bean;
        }
        ...
        public void methodThatUsesBean() {
            int timeout = calculateTimeout();
            bean.setTimeout(timeout);
            ...
        }
    }
    

提交回复
热议问题