I have the following nested null check which. Trying to make it readable via Optional
but how do I map a first element?
Stuck with following, unsure how to map this line
vo.getSomething().getAnother().get(0)
I am stuck on the 3rd line
Optional.of(vo.getSomething)
.map(Something::getAnother)
.map(List<Another>::get(0)) // will not work
Here is a working null check. I am trying to clean it up with Optional.
if(vo.getSomething() != null){
if(vo.getSomething().getAnother() != null){
if(vo.getSomething().getAnother().get(0) != null){
if(vo.getSomething().getAnother().get(0).getInner() != null){
if(vo.getSomething().getAnother().get(0).getInner() != null){
if(vo.getSomething().getAnother().get(0).getInner().get(0) != null){
return vo.getSomething().getAnother().get(0).getInner().get(0).getProductName();
}
}
}
}
}
}