the blog for developers

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

About the author

stephan Stephan Schmidt has been working with internet technologies for the last 20 years. He was head of development, consultant and CTO and is a speaker, author and blog writer. He specializes in organizing and optimizing software development helping companies by increasing productivity with lean software development and agile methodologies. Want to know more? All views are only his own. You can find him on Google +

You can leave a Reply here. Of course, you should follow me on twitter here.

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.

Leave a reply.

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

http://projectlombok.org/ has it and much more ;-)

Leave a Reply

What people wrote somewhere else:

Additional comments powered by BackType

Guide to CodeMonkeyism

Over the last 4 years I wrote many articles on this blog. To make it easier for you to find the relevant ones, I've organized them into topics.

Top 10

6 reasons why my VC funded startup did fail

Go Ahead: Next Generation Java Programming Style

Java Interview questions: Write a String Reverser

The dark side of NoSQL

7 Bad Signs not to Work for a Software Company or Startup

Is Java dead?

Scala vs. Clojure

Never, never, never use String in Java

No future for functional programming in 2008 – Scala, F# and Nu

Clojure vs Scala, Part 2

Java Developer

Is Java Dead?

Go Ahead: Next Generation Java Programming Style

Be careful with magical code

All variables in Java must be final

Never, never, never use String in Java

Bending Java: More readable code with methods that do nothing?

NoSQL Guy

NoSQL: The Dawn of Polyglot Persistence

The dark side of NoSQL

Essential storage tradeoff: Simple Reads vs. Simple Writes

Sharding destroys the goals of your relational database

The unholy legacy of databases

Startup/CTO

Development Dream Teams

6 reasons why my VC funded startup did fail

American vs. European style of Software Development

12 Things to Reduce Your Lead Time and Time to Market

The high cost of overhead when working in parallel

Essential storage tradeoff: Simple Reads vs. Simple Writes

Job Seeker

Another Good (Java) Interview Question

7 Bad Signs not to Work for a Software Company or Startup

Java Interview questions: Write a String Reverser (and use Recursion!)

Java Interview questions: Multiple Inheritance

As a Manager: What I value in developers

Top 10 Tips (+1) to Get a Pay Raise

Agilist

What Developers Need to Know About Agile

5 Practices Better to Change in Your Scrum Implementation

Scrum is not about engineering practices

ScrumMaster and ZenMaster: The joke of certification

What is Trans-Scrum?