javaconstructorclass-constructors

Passing custom object into another constructor


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


Solution

  • 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);
    }