Kevlin Henney wrote:
To really demonstrate autoboxing you need to allow the compiler to convert from int to Integer:

    Integer x = 1000;
    Integer y = 1000;

However, if you are after interesting counterintuitive corner cases, change the constant to 100:

    Integer x = 100;
    Integer y = 100;

A direct equality comparison will now compare true because, by default, the JVM caches the Integer objects for values from -128 to +127 (the range can be extended as an optimisation).

In other words, your corner case has a corner case. Magic.

I consider that just poor design on the part of the Java designers.
Any language that has multiple distinct representations
for the same set of values, that aren't entirely semantically
equivalent without explicit conversions, is just broken.

In Java's case, it's just a performance hack embedded
into the language that wasn't a good idea to start with,
and that's just sprawled and mutated over versions into
something clumsy and brittle.

Now, if you want examples of magic, probably the best
place to look is perl, which is filled with the stuff,
as tasty cheese is filled with mould.

Here, let me show you it:

  http://stackoverflow.com/questions/161872/hidden-features-of-perl

--
Frank Wales [fr...@limov.com]

--
The Open University is incorporated by Royal Charter (RC 000391), an exempt charity 
in England & Wales and a charity registered in Scotland (SC 038302).

Reply via email to