Learn how to use the new toString() code-generation ability in Eclipse Galileo along with hashCode(), equals(), and setter/getter generation to cut down on the amount of work that goes into building the foundation of a Java class. Learn which code you have to type and which code you can generate, making a lot less work for you.
- Posted by: Frank Charles
- Posted on: August 24 2009 07:30 EDT
- This has been around for a while. by Andrew Pitt on August 24 2009 16:51 EDT
- Re: Faster Java coding in Eclipse Galileo by Reik Schatz on August 25 2009 09:06 EDT
I've been using the apache commons *Builders for a long time now, this doesn't really add much. Also, the getter/setter generation mentioned in the article has been available for quite a while now. If you're interested in org.apache.commons.lang.builder.: ToStringBuilder EqualsBuilder HashCodeBuilder Each offers a reflexive version, and the ability to simply append the properties you wish to use instead. Not that it isn't nice to have some right-click method to do the same thing, but the reflexive builders mentioned above will also produce less code.
- One nice thing is that you can indeed configure the Galileo toString wizard to use apache commons-lang's ToStringBuilder. To do so, select "Custom toString builder" as the Code Style option in the Generate toString() wizard. Then, using the "Configure..." button, choose org.apache.commons.lang.builder.ToStringBuilder as the Builder class (this, of course, requires that the commons-lang.jar be in your classpath). Those of you that are Spring inclined can also choose org.springframework.core.style.ToStringCreator. Eclipse will nicely fill the other fields for you. One sad thing is that Galileo doesn't provides you the same flexibility for the equals and hashCode methods. I hope that the same flexible wizard will be provided for equals and hashCode methods in the near future. During this time I will continue to hand-code my equals and hashCode methods using commons-lang's EqualBuilder and HashCodeBuilder. ZartC
I like the fact that you can substitute your own ToString builder. Like you mentioned, it would be nice to also be able to substitute your own Equals and HashCode builders. If you could easily substitute the default builders with the apache versions, and have them generated automatically when you create a new class, that would be very handy indeed.
Lol Killerfeature. This has been in IntelliJ since 5 years or so.