Programming is hard by Stephan Schmidt

@Getter annotation?

With 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;
}

If you liked this post, subscribe to my free full RSS feed.
Filed under: Annotations, Java 7

You can share this post!
Do you want to tell others about this article? Use the social bookmark icons to submit this artice to the service of your choice. Thanks.

Get free updates by email

If you did like this article you can get free updates with your RSS reader, you can follow me on Twitter or get free update to new posts by email. Enter your email:

 
About the author: Stephan has been working as a head of development and CTO. He has experiences in different technologies since 20 years including Java, Rails and Python. Stephans main field of interest is maintainablity and productivity in software development. Want to know more? All views are only his own.

Comments

Not entirely sure what you’re looking for, but you can do this with PropertyDescriptors.

stephan

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)

stephan

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.

Peter Lawrey

Another option, if the getter doesn’t do anything why not have a public final field?

stephan

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)

Jim

Quite a lot of discussion about this for Java 7:
http://tech.puredanger.com/java7#property

stephan

@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

Leave a Reply