@Getter annotation?
Published November 24th, 2007 in Annotations, Java 7With all the innovation in annotations, see Web Beans or Google Guice, just a saturday morning idea: Why not drop the annoying get* convention and replace it with some annotations? The API wouldn’t be as short, but the usage of a getter looks nicer and more fluent. And of course the IDE could hide the @Getter annotation, just as it hides the imports.
@Getter
public Context context() {
return context;
}
public Context getContext() {
return context;
}
Not entirely sure what you’re looking for, but you can do this with PropertyDescriptors.
Care to explain?
And then we make the parenthesis..
or just use scala ;-)
http://www.scala-lang.org/docu/files/api/scala/reflect/BeanProperty.html
(with val only get* will be produced)
Or use Groovy ;-) Scala is nice indeed. I don’t think it will get into the mainstream but it might show the way for a Java future (type inference, actors, class matching).
And of course: away with the parenthesis.
Another option, if the getter doesn’t do anything why not have a public final field?
A final public field makes it hard to change the behavior in the future I guess. Groovy/Scala/Ruby properties would be best. Hope for Java 7.
The lowercase getter is already used: It is the accessor to a final field. (See ordinal(), name() in Enum)
When I look at the discussions over Java 7 I am all but sure if I want to use this Java. Luckily there are Scala and C#. I don’t want a Smalltalk Java nor a Google Java (interesting that the Google Collections look horrible now but will look nice as soon as the Google suggestions will make it into the language)
Quite a lot of discussion about this for Java 7:
http://tech.puredanger.com/java7#property
@Carsten, @Jim: Yes, I’m following the discussion with much interest. Let’s hope Java gets better property handling with Java 7. Perhaps even something Javascript like (which is beautiful in it’s simplicity), combining properties with BCGA:
myclass.setX = {int x => this.x = x} myclass.x = 3