2/02/2008

Life without Getters and Setters

Over at Stephan's Blog he mentioned an idea that I had the other day as well. Back when Java Beans came around the getter and setter notation was a convention to help frameworks determine what the properties of an object were. But, now that we have annotations why, other than legacy reasons, would we continue to use them? Just annotate the method with @Get, @Set, or @Property.

The cool thing is that if legacy frameworks used java.bean.Inspector class, you could encapsulate the new fangled annotation style properties inside it, and old frameworks wouldn't need to know that it changed.

This would get us closer to something I'd like in Java 7. Uniform Access Principle. No more would we need to write getter and setters. It's actually a feature that wouldn't harm the language, and you could turn it off with annotations if you had a need. The cool thing about it is that it's completely compiler driven. No language changes. Maybe if we can't get agreement on closures how about this for Java 7?