Community
Participate
Working Groups
In addition to an annotation for immutable value types, we should have one for mutable Java Beans. @Bean seems to be a good name.
Many times, @Data is not that applicable on day today basis especially creating a constructor with all fields in it. @Bean would be nice. If that name is too generic, we can also consider @ValueBean or @ValueObject or @Pojo or @Dto (data transfer object). I think it should do following. 1. Make all fields Read/Write properties 2. Generate ToString for the bean 3. Generate equals/hashcode based on the user's settings
The newly introduced @Getter and @Setter can be used on class level as well. Implementing value based equals/hashcode for mutable data types is a bad idea, as the contract of hashCode forbids to change it. Still, if you really want to have it there is @EqualsHashCode. For generating 'toString' there is a dedicated annotation @ToString, which can be used independently. Still @Getter @Setter class Person { } doesn't read as nicely as @Bean class Person { } What do others think? Should we have @Bean (w/o equals & hashcode)? See also https://git.eclipse.org/r/#/c/28796/
We found a way to harmonize @Getter, @Setter, @Property and @Bean. It will be called @Accessors. Annotated on a field, it creates a getter and setter for that field. Annotated on the class, it creates getters and setters for all fields and also a constructor that takes all final fields. The annotation will be configurable, so you can specify the visibility of the getter and the setter and even opt out of having them. So if you have @Accessors on a class, you can still exclude a single field. @Accessors class Person { val int id //becomes a constructor argument and gets a public getter String firstName //public getter and setter @Accessors(PROTECTED_GETTER) String lastName //no setter, protected getter } The @Data annotation will also respect the @Accessors, so you could for instance have a @Data class with only protected getters instead of public ones.
Pushed to review https://git.eclipse.org/r/#/c/29536/
Requested via bug 522520. -M.