I have an object as follow :
Class A {
B b;
// getters
}
Class B {
C c;
// getters
}
Class C {
D d
// getters
}
I want to get value on A.getB().getC().getD(
) and not to get NullPointerExceptions
I want to avoid writting something like :
if (A.getB() == null) {
return null
}
else if (A.getB().getC()) == null) {
return null
}
else
return A.getB().getC().getD()
Is there a more proper way to do that ?
FYI Optional.ofNullable is not working too.
Here is a screenshot :