Home > Blockchain >  Passing custom object into another constructor
Passing custom object into another constructor

Time:01-14

I have a custom Class Employee. Now in the Customer Class in the first construcor I want to pass a dummy employee object for the second constructor. How can I do this?

Customer Class excerpt

CodePudding user response:

Please ask yourself, "is a design I really want?"

You can pass it null or a dummy Employee.

static final Employee DUMMY_VALUE = new Employee();

public Customer(String name, int age){
    this(name, age, "", DUMMY_VALUE);
}

CodePudding user response:

The solution was to just pass null for the Employee object!

  •  Tags:  
  • Related