.equals() VS ==

July 28, 2008

Just a small post to tell you an other story of my daily learning of Java programming.

Always use .equals() method instead of ==

In our application, I was always comparing objects using ==. All worked fine until …. we decided to use a database to persist our objects across application launches and to avoid OutOfMemoryError. Why ???

The answer is easy, each time an object is retrieved from the database, we create a NEW Java object initialized with the values stored in the database. Thus, the == operator is no more valid between to different Java objects representing the same “conceptual object”.

After overriding the equals and hashCode methos for my persitent objects I had to refactor all my lines of code to replace all == by equals method ;o)


Keep Your Runtime Workspace Clean

July 16, 2008

Still working with a lot of Eclipse views, I got today a really strange behavior … The Window -> Show View menu creating my multi instance view with a null secondary id didn’t generate a call to the createPartControl method of my view !!!!!!

After several debug sessions I decided to clean my runtime workspace and the problem went ago. I guess this workspace was in a wrong state resulting of a lot of open and “dirty kill”.

Conclusion, just keep your runtime workspace clean when developing eclipse plug-ins.