Skip to content

Instantly share code, notes, and snippets.

@BalicantaYao
Created August 25, 2014 14:29
Show Gist options
  • Save BalicantaYao/ee58fefa700c11852076 to your computer and use it in GitHub Desktop.
Save BalicantaYao/ee58fefa700c11852076 to your computer and use it in GitHub Desktop.
PassByValue.java
private static void runCase2() {
int j = 10;
Point point = new Point(4, 4);
logger.info("Before Modify Point {}, j ={}", point, j);
setPointWithAssign(point, j);
logger.info("After Modify Point {}, j ={}", point, j);
// Result
// Before Modify Point Point{y=4, x=4}, j =10
// During Modify Point Point{y=5, x=5}, j =20
// After Modify Point Point{y=4, x=4}, j =10
}
private static void setPointWithAssign(Point pointInst, int j) {
pointInst = new Point(5, 5);
j = 20;
logger.info("During Modify Point {}, j ={}", pointInst, j);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment