Follow up – Java Musings

So, I haven’t written anything for a long time and that’s an unfortunate situation so I decided to sit down and get something written. One of the items that I’ve had in mind for a bit is a follow up to a post I did back in February regarding something I was wishing for in the java language. My original post was a bit more robust but in the end all I really wanted was to stop having to create general getters and setters for every field in every class. The amount of boiler plate for common stuff was just getting on my nerves.

I was quite pleased, and honestly a bit surprised, when I started working with objective-c and found the property mechanic. For those that aren’t aware, objective-c provides the ability to declare a property for a class within its declaration:@property (attributes) Type name;

And then within the implementation you just need to do: @synthesize name;

This will tell the compiler to automatically generate a getter and a setter (unless read only) without all the unnecessary cruft of the manual implementations. How wonderful is that? It is concise, easy to read, allows basic customization via the attributes, and still gives you the ability to override method creation as necessary.

I know it doesn’t really mean anything but I still say it would go great with Java if they could implement it.

Leave a comment