Using IDE generator/wizard

Using IDE generator/wizard allows developper to produce the getters and setters' code and sometimes to manage them. It's the most using solution (but I expect a change, like moving to GetSet's practice :-) ). Lot of IDE only provide facilities to generate the code, not to maintain it. And the source code is always "noisy" with those trivial/plumbing codes.

[top]

Using annotations to create getter and setter

Using annotations and a tool creating or introducing getter/setter method at compile time or run time. But developpers are restricted to cases planned by generator's vendor, they can't insert free code into a generated getter/setter method.

Current IDE doesn't support this feature.

[top]

Using annotations to mark attribute as property

See Say No to Properties Boilerplate!. The implementation like propjavac requires jdk 1.6 and optionnaly post/pre-compiler.

Current IDE doesn't support this feature.

[top]

Adding property as language feature
  • like C#, D, ...
  • One proposal is when objects try to access an property, the JVM use accessors methods if they exist or access directly to the attribute.
  • Other proposal: the compiler always create setter and getter if not exist.
  • Or an overloading mechanism of "=" and "." (using "get" and "set").
  • What is planned for Java 7 (Dolphin).
  • ...

This way isn't for today or jdk 1.6, it needs to follow the JCP and after, the update of developpement's tools : jdk, IDE,...

[top]

The "SmartFields"

The "SmartFields" solution from Christopher defines each property as an instance of Field. Field (and children class) provides getter, setter (and may be adapter). So instead of "foo.setBar(3)", you write "foo.bar.setValue(3)". It's similar to some mapping library.

It has some advantage, but IMO it's produce too heavy (create lots of overhead) or complicated "struct". And I don't know how it works with ORM or view framework.

[top]