Java??????У?java.lang.Object
???????????? ???????[ 2014/5/29 13:22:02 ] ????????Java java.lang.Object
????????????Java???/?????????????????????????
????4.public final native Class<?> getClass();
????getClass()??????native??????????????Object??????????/??????????Class<?>??Ч????Object.class?????
?????????????"?????"???????Java?У????????????????????????????????????????????????????????????????????????????????????????????ε?????????????Щ???????????綼???????????????????????????????а??????и???????????????????Java?????????????????Class??????????????????е???Щ????????????????????????????????Class??????????????????????????????????"?????"??
???????????????漰??Java?е?????????????????????????????????????
????5.public boolean equals(Object obj);
????==??equals??Java?о??????????????????==??equals??????
????==???????????????????????????????????д洢?????????????????洢????????????????
????equals???????????????????????????????????????????/?????
???????????????????????????????????????String???С?????????Object???й???equals()????????壺
????1 public boolean equals(Object obj) {
????2 return (this == obj);
????3 }
???????????Object?????equals()????????????????==????==???????????塣??????????????????equals()??????
????equlas()???????????????????ж????????????????????ж??????????????????
???????????object???У???????==????????????????????????????п????????????????????????????塣??String?????????????????????????????????????????塣??????????????????????????????????????????????????????дequals()????????????????????????????丸???equals()?????object????
???????3???????????????????User bean???????????????????????uid?????????????????User????????User???????????????дequals???????User???????????
1 package com.corn.objectsummary;
2
3 public class User {
4
5 private int uid;
6 private String name;
7 private int age;
8
9 public int getUid() {
10 return uid;
11 }
12
13 public void setUid(int uid) {
14 this.uid = uid;
15 }
16
17 protected String getName() {
18 return name;
19 }
20
21 public void setName(String name) {
22 this.name = name;
23 }
24
25 public int getAge() {
26 return age;
27 }
28
29 public void setAge(int age) {
30 this.age = age;
31 }
32
33 @Override
34 public boolean equals(Object obj) {
35 if (obj == null || !(obj instanceof User)) {
36 return false;
37 }
38 if (((User) obj).getUid() == this.getUid()) {
39 return true;
40 }
41 return false;
42 }
43 }
1 package com.corn.objectsummary;
2
3 public class ObjectTest implements Cloneable {
4
5 public static void main(String[] args) {
6 User u1 = new User();
7 u1.setUid(111);
8 u1.setName("????");
9
10 User u2 = new User();
11 u2.setUid(111);
12 u2.setName("??????");
13
14 System.out.println(u1.equals(u2)); //????true
15 }
16
17 }
|
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11