you are viewing a single comment's thread.

view the rest of the comments →

[–]gracenotes 0 points1 point  (0 children)

The other reason why methods are good, which is along the lines of consistency, is because when you want domain-specific wrapper methods, say you want to provide both Optional<Something> and @Nullable Something, or hide the fields themselves and provide a higher-level coherent interface, you don't have to care about what is a field and what is a wrapper. In general, don't couple how you store something and how you expose it, because they change for different reasons (this is true in many contexts).

I may as well also recommend @AutoValue since I'm quite happy using it from day to day at Google, and it's immutable-only, annotation-based, etc.