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.

Back in the sixties, the autocode for the Atlas machine at Harwell had a fine piece of magic. As an outsider, I could book for an occasional week there, and while I was there I could run programs twice a day iirc. I once spent two of those 7 days trying to find out why my program wouldn't work, panicking desperately about meeting my target, before discovering that of its 128 registers (called B-lines), the one I had chosen to use was fitted with a hardware conversion to return log-2 of any quantity stored in it.

All the higher-numbered B-lines silently did special things, apparently. Great if you knew about them. Tough otherwise.

(For those of you who came late to the party and missed the early days, an 'autocode' was a slightly-Englished version of machine code. Bit like a penny-farthing - if you stayed on, people admired you, but when you fell off it really showed.)


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