[quote]byte[] buff = new byte[]{'H', 'e', 'l', 'l', 'o'};
String str1 = new String(buff);
String str2 = "Hello";
if(str1 == "Hello"){
System.out.println("Every good programming language");
}
else if(str1 == str2){
System.out.println("lolwut?");
}
else{
System.out.println("Java " + (str1.equals("Hello") ? "sucks" : "doesn't suck"));
}[/quote]
Output:[quote]Java sucks[/quote]
-
I know your feels.
-
McRibbitt
They took away my Halo 3 pfp :( - old
-
I'm not too sure why you'd compare strings on reference rather than value. Anywho, I've long since passed the stage where I bother questioning the strange goings on in the land of programming. It's almost as if the people who design programming languages are all just massive trolls who delight in causing pain and suffering to others.
-
This picture describes my feels.
-
I really don't like Java, but you're using == wrong. == compares reference equality, so for two objects it only compares their references (like pointer addresses in C/C++). You're supposed to use .equals for objects (those that implement it, that is), and if you change it to .equals then it works like expected (for both conditionals). If you know that and are complaining about syntax then I guess that's valid (Java has atrocious syntax), but then you're left with === like in javascript or php which is worse imo.
-
I'm happy to admit that I have no idea what the point of the OP is.
-
I thought Java sucks because of the massive security holes that have existed in the program from Day One. Which they patched. Only the patch introduced even bigger security holes. So big that even Java's creators said to turn it off and shut it down. This happened months ago.
-
Edited by HurtfulTurkey: 3/20/2013 5:13:31 AMFTFY Use .equals, not ==. [url=http://ideone.com/vGaao2]Alternative syntax.[/url] ↓↓↓ What he said.
-
now make it say poop
-
-
hue hue hue
-
alright...