Created
June 27, 2011 12:48
-
-
Save Keruspe/1048790 to your computer and use it in GitHub Desktop.
Why I do hate java
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 Ref { | |
public void inc1(int i) { | |
++i; | |
} | |
public void inc2(Integer i) { | |
++i; | |
} | |
public static void main(String[] args) { | |
int foo = 32; | |
Integer bar = 41; | |
Ref r = new Ref(); | |
System.out.println("Expected: 32x41\nGot: " + foo + "x" + bar); | |
r.inc1(foo); | |
System.out.println("Expected: 32x41\nGot: " + foo + "x" + bar); | |
r.inc2(bar); | |
System.out.println("Expected: 32x42\nGot: " + foo + "x" + bar); | |
r.inc1(bar); | |
System.out.println("Expected: 32x42\nGot: " + foo + "x" + bar); | |
r.inc2(foo); | |
System.out.println("Expected: 32x42\nGot: " + foo + "x" + bar); | |
/* Output: | |
Expected: 32x41 | |
Got: 32x41 | |
Expected: 32x41 | |
Got: 32x41 | |
Expected: 32x42 | |
Got: 32x41 | |
Expected: 32x42 | |
Got: 32x41 | |
Expected: 32x42 | |
Got: 32x41 | |
*/ | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Oh, I see… I wasn’t quite paying enough attention. Yes, it is odd how Integer is an effectively immutable object like that, which is different from most other Java objects.
I’m not a particularly big fan of Java myself, or I might have noticed that sooner ☺