Skip to content

Commit 411c836

Browse files
update method reference
1 parent 8cf4c70 commit 411c836

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

src/ABasic/A7Method/MethodReference.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,32 @@
33
public class MethodReference {
44
public static void main(String[] args) {
55
Person person=new Person("name", 18, "black");
6+
// person1还是person1,hashCode相同
67
Person person1=new Person("name1", 19);
78
System.out.println(person1.toString());
89
copyAttribute(person, person1);
910
System.out.println(person1.toString());
11+
// person2发生了变化,hashCode不同
12+
Person person2=new Person("name2", 20);
13+
System.out.println(person2.toString());
14+
person2=copyAttribute2();
15+
System.out.println(person2);
16+
person2=copyAttribute3();
17+
System.out.println(person2);
1018
}
1119

1220
public static void copyAttribute(Person person, Person person1){
1321
person1.setEyeColor(person.getEyeColor());
1422
}
1523

24+
public static Person copyAttribute2(){
25+
Person person=new Person("name", 20, "red");
26+
return person;
27+
}
28+
29+
public static Person copyAttribute3(){
30+
Person person=new Person("name", 20, "blue");
31+
return person;
32+
}
33+
1634
}

src/ABasic/A7Method/Person.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public void setBirthday(Date birthday) {
6767
*/
6868
@Override
6969
public String toString() {
70-
String string="name: "+name+", age: "+age+", eyeColor: "+eyeColor;
70+
String string="hashCode: "+hashCode()+", name: "+name+", age: "+age+", eyeColor: "+eyeColor;
7171
return string;
7272
}
7373
}

0 commit comments

Comments
 (0)