Last active
May 2, 2019 18:58
-
-
Save rodrigoSaladoAnaya/79c718f7e838cbd0d502b67f05956a7c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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