Hacker News new | ask | show | jobs
by V-2 4174 days ago
Besides, getters and setters are debuggable. They allow you for setting breakpoints, adding Log calls etc... Not so in case of fields.

It would be nice to have some syntax sugar for defining properties more tersely though, like in C#.

1 comments

Project Lombok allows you to use annotations to create getters and setters:

  @Getter
  private String author;
  @Getter
  private String title;
Or, on the class, here with a fluent (non-JavaBean) API:

  @Data
  @Accessors(fluent = true) // experimental
  public class Article {
    private String author;
    ...
  }