Last active
October 1, 2019 13:32
-
-
Save loongest/a5ef7ed020b9493a5bb5b79113e5e85d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ObjReferenceTest { | |
private int age = 12; | |
public static void main(String[] args) { | |
ObjReferenceTest obj = new ObjReferenceTest(); | |
System.out.println("[initially]"); | |
System.out.println("Age = " + obj.age + " , hashcode = " + System.identityHashCode(obj) + "\n"); | |
obj.changeAge99(obj); | |
System.out.println("Age = " + obj.age + " , hashcode = " + System.identityHashCode(obj) + "\n"); | |
obj.changeAge88(obj.age); | |
System.out.println("Age = " + obj.age + ", hashcode = " + System.identityHashCode(obj.age)); | |
} | |
private void changeAge99(PrimitiveAsParameter obj) { | |
System.out.println("[changeAge99] Parameter's hashcode = " + obj.hashCode()); | |
obj.age = 99; | |
} | |
private void changeAge88(int age) { | |
System.out.println("[changeAge88] age hashcode = " + System.identityHashCode(age)); | |
age = 88; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment