Closed GoogleCodeExporter closed 9 years ago
Some Thoughts/Possible Alternatives:
- In each primitive class have a defaultIfNull(T value, T default), maybe with defaultIfNull(T value) delegating to the 2 param. version with a suitable default (ex 0 for numeric primitives)
- Functions<T, T> defaultIfNullFunction(T value, T default) in Functions
Original comment by boppenh...@google.com
on 1 Oct 2010 at 6:23
Or...
Objects.firstNotNull(input, 0).intValue();
Original comment by jim.andreou
on 1 Oct 2010 at 7:42
I was just trying to stick to the naming convention used for Strings.nullToEmpty
Original comment by ali.bagh...@gmail.com
on 1 Oct 2010 at 12:24
I'd use Jim's suggestion.
int value = (int) Objects.firstNonNull(input, 0);
Original comment by kevinb@google.com
on 4 Oct 2010 at 1:54
Thanks for that.
Also, I have something like the following:
y = z == null ? "" : z.getX();
I know this one is a bit tricky, but is there any helper method for this kind
of thing?
Original comment by ali.bagh...@gmail.com
on 4 Oct 2010 at 10:51
This issue has been migrated to GitHub.
It can be found at https://github.com/google/guava/issues/<id>
Original comment by cgdecker@google.com
on 1 Nov 2014 at 4:15
Original comment by cgdecker@google.com
on 3 Nov 2014 at 9:09
Original issue reported on code.google.com by
ali.bagh...@gmail.com
on 1 Oct 2010 at 4:27