How to instantiante object & call setter on same line?

前端 未结 8 1299
一个人的身影
一个人的身影 2020-12-10 10:49

If I have an Employee class with a default constructor:

private String firstName;
public Employee(){}

and a setter:

         


        
8条回答
  •  误落风尘
    2020-12-10 11:26

    The method serFirstName is of return type void (nothing). Try:

    public Employee setFirstName(String fname) {
      this.firstName = fname;
      return this;
    }
    

提交回复
热议问题