Java Getters and Setters

Verhogen picture Verhogen · Dec 15, 2009 · Viewed 50.2k times · Source

Is there a better standard way to create getters and setters in Java?

It is quite verbose to have to explicitly define getters and setters for each variable. Is there a better standard annotations approach?

Does Spring have something like this?

Even C# has properties.

Answer

Carl Smotricz picture Carl Smotricz · Dec 15, 2009

I'm not sure if you'd consider it 'standard', but Project Lombok addresses this problem. They use annotations to replace much of the verbosity of Java.

Some people are looking at alternative Java sibling languages, such as Groovy or Scala. I'm afraid it will take some years -if at all- before the JSR figures out a "standardized" way to "fix" this in Java proper.