This has been written about by others but I’m going to comment on it as I did run into it tonight.
I’ll start by saying that I sit on the fence with regards to the use of autoboxing in java5. Normally I think it’s alright but I did run into a situation this evening where the transitivity properties of equality didn’t hold as I expected (well I expected them to behave as they did, but it did run slightly counter to the definition of transitivity depending on how the code was written).
Code:
public class Test {
public static void main(String[] args)
{
Long int1 = new Long(1);
long int2 = new Long(1);
Long int3 = new Long(1);
System.out.println(int1 == int2);
System.out.println(int2 == int3);
System.out.println(int1 == int3);
}
}
Output:
true
true
false
However, if we swap 1L in for ‘new Long(1)’, than transitivity holds and A == B && B == C && A == C.
Nothing more than food for thought.
It’s almost too easy to unconsciously make use of autoboxing so we should weigh the benefits of simplicity with the potential for some unexpected results.
-
Windows Live Writer isn’t bad Until recently, the bulk of my writing was done on a Mac using Ecto. I was looking for a suitable publishing tool for Windows and was directed towards ...
-
Pet Peeve: Don’t email my password to me in plain text You know the drill.
Signup for some random service on the internet
Receive a confirmation email with your account information
or
Forget a password for some random service ...
-
Eclipise Memory Analyzer (MAT) I must say the Eclipse Memory Analyzer looks pretty slick. There is some pretty good material over on the developers blog. Lastly, there was a talk on it ...
-
Open-source Web-based Code Review Tool: Rietveld Guido van Rossum, of Python fame, has recently released a Django-based application that enables web-based code reviews... Rietveld.
It supports any language and currently can hook into Subversion repositories. You ...
-
An implementation of the JVM in Javascript? Caught this over on JavaPosse Google Groups.
Essentially, some bright fellows over in Japan have developed a bytecode->javascript compiler. There's a demo floating around that took a Tetris ...
Latest Entries
- Windows Live Writer isn’t bad
- Playing around with Rails again
- Lessons Learned as a Project Lead
- Good ANTLR Resource
- Testing with Unitils
- Headed to Kelowna for a short vacation (and the laptop stays behind)
- Seam + Groovy + Maven : Nice Simple Hibernate POJOs
- Pet Peeve: Don’t email my password to me in plain text
- Eclipise Memory Analyzer (MAT)
- caBIG Annual Meeting - A developers perspective
Blogroll
No Comments
Leave a Comment
trackback address