Is there a shortcut to execute something only if its not null?
This question already has an answer here:
In Java 8:
static <T> boolean notNull(Supplier<T> getter, Predicate<T> tester) {
T x = getter.get();
return x != null && tester.test(x);
}
if (notNull(something::getThatObject, MyObject::someBooleanFunction)) {
...
}
If this style is new to the readers, one should keep in mind, that full functional programming is a bit nicer.
Well Java 8 has got something called Optional. More details are at : http://www.oracle.com/technetwork/articles/java/java8-optional-2175753.html
不,我相当确信,没有办法做到比你所拥有的任何时间都短。
链接地址: http://www.djcxy.com/p/13296.html上一篇: Java:空检查的最佳实践