I've been tracking down a problem with the CompareToBuilder that's part of commons lang. If I had a boolean in my class, and if used the reflectionCompare method it was throwing a ClassCastException. It didn't make any sense to me.
Then I took at look at the source (soooo useful!) and I finally figured it out I think. (btw, a great site for seeing source of OS projects is this one).
At one point in the commons lang project they have this line:
comparison = ((Comparable) lhs).compareTo(rhs);
which was throwing a ClassCastException. Both lhs and rhs are "Objects". Can you see the problem?
When doing something reflexivly Java casts primitive types to their wrapper types (boolean become Boolean and int becomes Integer). I'm using Java 1.4.2 and Boolean doesn't implement Comparable. Doh!
Sometimes I really wish that they just made compareTo part of the Object class...
What is greater: true or false? In C false is 0, true is 1 (actually it is everything other than 0).
ReplyDeleteAlso, with eclipse I use Jad (java decompiler http://www.kpdus.com/jad.html) with a jadclipse plugin. Can be very useful.
Someone made a call what is greater...
ReplyDeletehttp://java.sun.com/j2se/1.5.0/docs/api/java/lang/Boolean.html#compareTo(java.lang.Boolean)
I was looking for a quote... something about "truth is greater still..." or something cheezy, but no luck on my part. :-/
How does this sound: "truth is greater unless lie is really really big".
ReplyDeleteIn any case, at least now it's settled, Boolean has compareTo method (in 1.5).
I now know that the latin I had to do for my schooling should have been a breeze compared to the "new milleniun language" that you use in this entry. The uneducated people like me and my friend Frank (www.mytrailerpark.com)just read this and it sounds like potty mouth. Seriously, reread it to yourself and think of us people from the "other side"(our heads are spinning). Oh well I know its just a blog so I'll just shut up now.
ReplyDeleteLater!!
I can see how if you don't have the background this post makes zero sense...
ReplyDeleteShould I ask where you found that webpage? Uhh... nevermind.
(I thought that your post was spam at first and I was going to delete it... I'm glad I saw checked the email address.)