HTML5 Canvas
Written by: Simon Sarris
Featured Refcardz: Top Refcardz:
  1. Apache Hadoop
  2. Web Driver
  3. MVVM
  4. REST
  5. ADO.NET
  1. HTML5
  2. Ajax
  3. jQuery Selectors
  4. CSS Part 1
  5. Git

Link Details

No hanging chads here, we promise! Login and vote now.
Link 6673 thumbnail
User 1 avatar

By rick
via coconut-palm-software.com
Published: Nov 12 2006 / 12:39

Much to my surprise yesterday, I discovered that Java 5 believes that 0 != 0 in certain situations.
  • 15
  • 0
  • 2887
  • 0

Comments

Add your comment
User 111696 avatar

bloid replied ago:

0 votes Vote down Vote up Reply

I firmly believe that autoboxing should be removed from the language...

Well...not removed, but we should go back in time, and never add it in :-/

User 182143 avatar

mezmo replied ago:

0 votes Vote down Vote up Reply

I would agree, the whole mess of syntactic sugar that is Java 5, generics, for each, even enums, roll them back and pretend they never happened. I think the phrase, "They only exist to the compiler" was the key indicator they were a mistake.

User 194680 avatar

bonlebon replied ago:

0 votes Vote down Vote up Reply

OMG so Java 5 IS a philosophical language.

To any guy that belongs to the JSR approval process: please stop adding stuff to Java and leave the wacky stuff to frameworks.

User 201649 avatar

jefu replied ago:

0 votes Vote down Vote up Reply

The generics are useful (though ugly and sometimes a pain), enums are ok but not overly useful, and the foreach is quite nice and very useful (though not really useful enough - why is there no way to do something like a foreach over a range of integers (to remove the usual counted loop)? Or even better, a foreach over something like a cross-product of ranges?).

But boxed types. Ewww! Ick! A very bad idea that is pretty much guaranteed to lead to even worse surprises than the one mentioned here.

User 190346 avatar

ilazarte replied ago:

0 votes Vote down Vote up Reply

submit it as a bug and move on... I think a better title for this post, Long.equals Bug?
Not sure how it turns into "Java 5 Is Inherently Flawed!1!"

User 209310 avatar

metheus replied ago:

0 votes Vote down Vote up Reply

There is nothing wrong with this behaviour. If you understand what is actually happening in this situation, it is quite simple. If you try to do the same thing in the old fashioned way you will get exactly the same result.

User 197767 avatar

csar replied ago:

2 votes Vote down Vote up Reply

It has nothing to do with Java 5, there had been a bug report on that 3 years ago: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4814906 (filed against 1.4.1)

I agree that autoboxing (which has nothing to do with the behavior) is sometimes quirky, but when going back in time I'd go back to 1995 and remove the non-object types from the language.

A Long is not an Integer. When an Integer should be used as an long or a Long as an int longValue() or intValue() has to be called.

The issue had been raised in a podcast (Javaposse) a year ago and Josh Bloch replied to that (Hard to find the reference as podcasts cannot be googled) saying that although it was possible to solve this issue locally, it would create severe problems in other parts that are very hard (if at all) to fix.

User 177489 avatar

jarcade replied ago:

0 votes Vote down Vote up Reply

Csar, absolutely correct. In my opinion, misunderstandings like this are a perfect case for the value of a good comp sci education.

User 203782 avatar

avrecko replied ago:

0 votes Vote down Vote up Reply

The problem is in the fact that primitives are not Objects and vice versa. The problem of autoboxing would have been totally avoided if numbers would be by default Objects. Soo there would be no int, short,...but Only Integer, Short,...

Java 7+ (what I would like to see)

Integer a = 7;
Inteber b = 8;

Integer c = a + b; // it would be evaluated internally as a.add(b);

and

Boolean same = (a == b); // would be evaluated as a.equals(b)

soo there would be no possibility of such problem. And finnaly

if you can do

String hello = "hello".toUpperCase();

I would also like to see that one can do

Integer x = 9.squareRoot();

User 71360 avatar

Thomas Boshell replied ago:

0 votes Vote down Vote up Reply

Of course not! Different objects are always different. Java does allow for one to change the compare functionality if one wants to change the comparrisons. Primatives are not objects, even with the magic

User 203782 avatar

avrecko replied ago:

0 votes Vote down Vote up Reply

My point is - if we would get rid of primitives and make Java 100 % OOP language such as Ruby then, this problem with autoboxing would not have existed.

Add your comment


Html tags not supported. Reply is editable for 5 minutes. Use [code lang="java|ruby|sql|css|xml"][/code] to post code snippets.

Voters For This Link (15)



Voters Against This Link (0)