I bumped my reply from another thread just because I don't believe that everybody
thinks this is normal. Have a close read:
I don't like autoboxing very much; below you'll see an example derived from an
original example by someone else posted in Sun's Java forum quite a while ago:
[Code=java]
import java.util.*;
public class Autoboxing {
public static void main(String[] args) {
Object foo = new Long(0xcafebabe deadbeefL);
List<Object> bars = new ArrayList<Objec t>();
bars.add(bool() ? (Long)foo : (Number)foo);
bars.add(bool() ? (Long)foo : (Long)foo);
bars.add(bool() ? (Long)foo : (Double)foo);
bars.add(bool() ? (Long)foo : ((Long)foo).lon gValue());
System.out.prin t("== :");
for (Object bar : bars)
System.out.prin t(" "+(foo == bar));
System.out.prin tln();
System.out.prin t("equals:");
for (Object bar : bars)
System.out.prin t(" "+foo.equals(ba r));
System.out.prin tln();
}
private static boolean bool() {
return true;
}
}[/code]
Output:
That's why I don't like autoboxing very much ...
kind regards,
Jos
thinks this is normal. Have a close read:
I don't like autoboxing very much; below you'll see an example derived from an
original example by someone else posted in Sun's Java forum quite a while ago:
[Code=java]
import java.util.*;
public class Autoboxing {
public static void main(String[] args) {
Object foo = new Long(0xcafebabe deadbeefL);
List<Object> bars = new ArrayList<Objec t>();
bars.add(bool() ? (Long)foo : (Number)foo);
bars.add(bool() ? (Long)foo : (Long)foo);
bars.add(bool() ? (Long)foo : (Double)foo);
bars.add(bool() ? (Long)foo : ((Long)foo).lon gValue());
System.out.prin t("== :");
for (Object bar : bars)
System.out.prin t(" "+(foo == bar));
System.out.prin tln();
System.out.prin t("equals:");
for (Object bar : bars)
System.out.prin t(" "+foo.equals(ba r));
System.out.prin tln();
}
private static boolean bool() {
return true;
}
}[/code]
Output:
Code:
== : true true false false equals: true true false true
kind regards,
Jos
Comment