views:

500

answers:

2

Is anyone aware of a library that uses the the techniques (annotations and classworking) described in this article for automatically generating the standard Object methods toString(), equals() and hashcode() for standard java classes?

A: 

I certainly haven't seen this and I'm not really sure what value would be gained from it. I find that automatic toString generation is not usually what you want when scouring log files and most IDEs will have tools to allow you to generate hashCode and equals implementations, although granted these do not automatically reflect any schema modifications within your class.

There would be 2 options for implementing this:

  1. Compile-time class annotation which is processed (e.g. by your IDE) to generate the relevant methods. Can annotations modify the generated bytecode of the classes they are declared in? I think this appraoch is a really bad idea because you can't tell what is going on by looking at your source code
  2. Runtime annotation on the relevant methods to indicate that they should be evaluated via the special mechanism. This still requires you to declare and annotate your methods and I'm also not sure how you would actually intercept method calls to use the annotation in any event
oxbow_lakes
+3  A: 

Yes, project Lombok does this. See http://projectlombok.org . It not only supports javac, but also Eclipse. So the methods are not in the source code, but are displayed in the outline view.

Bno
Very interesting, although I think I'll still with POJOs and an IDE
oxbow_lakes