What is the best practice for linking nested objects?
Say I have the following:
class Outer { private InnerA innerA;
and in my controller or service class I need to check the someString String variable of the InnerB class to make sure it is not null or not empty, so I do this:
if (getOuter().getInnerA().getInnerB().getSomeString() != null && !getOuter().getInnerA().getInnerB().getSomeString().equalsIgnoreCase("") { //do something }
For me, this looks dirty and can have problems if the nested objects themselves are zero.
Am I creating getters ans seters in parent objects for child objects checking null? Just wondering what was the best practice, if any, and / or what some of you do in your code?
java object reference nested
blong824
source share