Archiwum tagu ‘Java Killers’
Java Killers #001
Na blogu Pawła Szulca (również w wersji polskiej) można czasem znaleźć zagadki związane z Javą. Paweł nazywa je Java Killers.
Bardzo lubię je czytać a teraz sam mam taką zagadkę. Mam nadzieję, że dla Was będzie to choć trochę ciekawostka, ja byłem zdziwiony.
Oto kod:
public class Main {
public static void main(String[] args) {
Integer i1 = 1000;
Integer i2 = 1000;
if (i1 != i2) {
System.out.println("i1 and i2 are not the same");
}
Integer i3 = 10;
Integer i4 = 10;
if (i3 == i4) {
System.out.println("i3 and i4 are the same");
}
}
}
A oto wynik:
i1 and i2 are not the same i3 and i4 are the same
Co się takiego stało, że 1000 to nie 1000 ale 10 to już 10?