JavaScript is required to use Bungie.net

Tema libero

Naviga in una tempesta di discussioni disparate.
3/20/2013 4:48:03 AM
12

This is why Java sucks

[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]

Lingua:

 

Fate i bravi. Prima di postare date un'occhiata al nostro codice di condotta. Annulla Modifica Crea squadra Invia

Visualizza l'intera discussione
  • 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.

    Lingua:

     

    Fate i bravi. Prima di postare date un'occhiata al nostro codice di condotta. Annulla Modifica Crea squadra Invia

    2 Risposte
    Non ti è permesso visualizzare questo contenuto.
    ;
    preload icon
    preload icon
    preload icon