Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个自定义 Class Employee。现在在Customer第一个构造函数的类中,我想为第二个构造函数传递一个虚拟员工对象。我怎样才能做到这一点?
Employee
Customer
请问问自己,“是我真正想要的设计吗?”
你可以通过它null或一个 dummy Employee。
null
static final Employee DUMMY_VALUE = new Employee(); public Customer(String name, int age){ this(name, age, "", DUMMY_VALUE); }