Details
-
New Feature
-
Status: Resolved
-
Major
-
Resolution: Fixed
-
None
-
None
-
None
Description
I have a new suggestion about null handling.
I usually check a object is null or not before using it to avoid NPE.
It is pretty obvious, but It is quite cumbersome and has some overhead.
So I want to introduce the following null-safety methods in ObjectUtils class and make people easy to handle null without using if/else statement or Optional class, etc.
public static <T, R> R applyIfNotNull(final T object, final Function<T, R> function) { return object != null ? function.apply(object) : null; } public static <T> void acceptIfNotNull(final T object, final Consumer<T> consumer) { if (object != null) { consumer.accept(object); } }
What do you think about it?
If it looks good, I will implement this feature.
Attachments
Issue Links
- links to