You could have a look at Project Lombok as it tries to take the pain out of writing boiler plate Java code. It allows you to either use @Getter
and @Setter
annotations, which will provide getBlah()
and setBlah()
methods:
public class GetterSetterExample {
@Getter @Setter private int age = 10;
}
Or you can just use @Data
and it will automatically implement your hashCode()
, equals()
, toString()
and getter methods, along with setters on non-final fields:
@Data public class DataExample {
private String name;
}
Problems I have found with the project, however, are that it's all a bit voodoo, which can be off-putting, and that you have to install an Eclipse (or what ever) plugin to get auto compilation to work.