-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathEmployee.java
More file actions
46 lines (38 loc) · 1.08 KB
/
Employee.java
File metadata and controls
46 lines (38 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/**
* Demonstrate immutable class creation and its rules
*/
public final class Employee {
private final String name;
private final int salary;
private final int id;
private final Address address;
public Employee(String name, int salary, int id, Address address) {
this.name = name;
this.salary = salary;
this.id = id;
this.address = new Address(address.flatNum, address.lane1, address.lane2
, address.city, address.postCode);//deep clone
}
public String getName() {
return name;
}
public int getSalary() {
return salary;
}
public int getId() {
return id;
}
public Address getAddress() {
return new Address(address.flatNum, address.lane1,
address.lane2, address.city, address.postCode);
}
@Override
public String toString() {
return "Employee{" +
"name='" + name + '\'' +
", salary=" + salary +
", id=" + id +
", address=" + address +
'}';
}
}