-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRecordClassDemo.java
59 lines (55 loc) · 1.34 KB
/
RecordClassDemo.java
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
47
48
49
50
51
52
53
54
55
56
57
58
59
package Java17Features;
import java.util.Objects;
//class NitEmployee{
// int id;
// String name;
//
// public NitEmployee(int id, String name) {
// this.id = id;
// this.name = name;
// }
//
// public int getId() {
// return id;
// }
//
// public String getName() {
// return name;
// }
//
// @Override
// public String toString() {
// return "NitEmployee{" +
// "id=" + id +
// ", name='" + name + '\'' +
// '}';
// }
//
// @Override
// public boolean equals(Object o) {
// if (this == o) return true;
// if (o == null || getClass() != o.getClass()) return false;
// NitEmployee that = (NitEmployee) o;
// return id == that.id && Objects.equals(name, that.name);
// }
//
// @Override
// public int hashCode() {
// return Objects.hash(id, name);
// }
//}
record NitEmployee(int id,String name){
NitEmployee(){
this(0,"");
}
}
public class RecordClassDemo {
public static void main(String[] args) {
NitEmployee ne1 = new NitEmployee(1,"Dev Kumar");
NitEmployee ne2 = new NitEmployee(1,"Dev Kumar");
NitEmployee ne3 = new NitEmployee();
System.out.println(ne1);
System.out.println(ne1.equals(ne2));
System.out.println(ne1.name());
}
}