Tuesday, 27 July 2010

The Terrible Dangers of Autoboxing (Part 2)

Solution to part 1:
j is equal to m
j is equal to K
K is equal to m

The result of one of the Object being null, will of course cause a NullPointerException.

Part 2:

class Autoboxing


    public static void main(String[] args)
    {
        Integer a = 10;
        Integer b = 10;
        Integer c = 1000;
        Integer d = 1000;
        System.out.println(a == b); //true
        System.out.println(c == d); //false
    }

};

Please explain.

(Found it in my Linkedin groups "Sun Certified Java Programmer" here)


References

Most common gotchas in Java
http://vanillajava.blogspot.nl/2014/02/most-common-gotchas-in-java.html

No comments:

Post a Comment