Skip to content

Instantly share code, notes, and snippets.

@rodrigoSaladoAnaya
Last active May 2, 2019 18:58
Show Gist options
  • Save rodrigoSaladoAnaya/79c718f7e838cbd0d502b67f05956a7c to your computer and use it in GitHub Desktop.
Save rodrigoSaladoAnaya/79c718f7e838cbd0d502b67f05956a7c to your computer and use it in GitHub Desktop.
public static <V> V getSafe(Supplier<V> func) {
V res = null;
try {
res = func.get();
} catch (java.lang.NullPointerException e) { }
return res;
}
log.info("C: {}", getSafe(() -> a.getA().getC()));
/*
class C {
public C getC() {
return this;
}
}
class B {
private C c = new C();
public C getB() {
//return null;
return c.getC();
}
}
class A {
private B b = new B();
public C getA() {
return b.getB();
}
}/**/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment