-
Notifications
You must be signed in to change notification settings - Fork 273
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
immutable: Allow optional fields as null #35
Comments
BTW |
Thanks for the info - I will investigate the Getters alternative. |
Support for |
Awesome! Thanks! I will take a look. |
I've checked out this commit and it looks good! My only comment is that it doesn't work for primitive return types. I guess this makes sense because having I got around this by just using
where Maybe, maybe not... Anyway, this is awesome as it is - thanks again! |
We did thought-work on this with other contributors some time ago. The conclusion was that the best way for this is to use @Value.Default
public boolean defaultReport() {
return false;
} Also, you can use |
Yep - makes total sense. I guess it's making it clear what you want the default to be, and not just use the JVM default. Thanks! |
One comment from my colleagues when trying to persuade them to use Immutables to replace existing code is they don't like the use of Optional for optional fields.
Personally, I'm still undecided about this one, I can see arguments both for and against. If we were starting from a green field then I'd think I'd be happy using Optional.
The one tricky thing was that switching to Optional for legacy beans can cause really subtle bugs if you're not careful. E.g. imagine this legacy code:
Now if I change to an Immutables like this...
... I won't receive a compiler error, but my logic in the "if" is broken.
Could we just have, say, an @Value.Optional annotation (Or even use the @javax.annotation.Nullable one), to mark a field optional?
That way, code which uses the old nullable style can work without any changes.
Yes, I understand you're trading off one problem for another (ambiguity about when getFoo() will return null), but this might suit some people better.
Thanks!
The text was updated successfully, but these errors were encountered: