Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

6
  • objA.getB().getC().getD() == null Commented Feb 15, 2013 at 9:43
  • 1
    @GrijeshChauhan.. And what if getB() returned a null? Commented Feb 15, 2013 at 9:43
  • that is what i want to handle by returning false through that function.... Commented Feb 15, 2013 at 9:45
  • Any kind of dynamic null-check using (getter) methods may fail any time the methods have side-effects. So you probably come best off when you check each method individually. Using reflection and public fields this check may be possible. Commented Feb 15, 2013 at 9:50
  • It doesn't sound like a very good approach. Surely you care which one is null? Won't that affect how you handle it being null? ie. if flight.family.person.baggage is null, that's probably fine - this person just doesn't have any baggage. But if flight.family.person is null, that means a family hasn't got any people - which is a serious error. Commented Feb 15, 2013 at 9:50