Как получить доступ к свойству глубоко вложенного объекта простым способом?JAVA

Программисты JAVA общаются здесь
Гость
Как получить доступ к свойству глубоко вложенного объекта простым способом?

Сообщение Гость »


an A object contains a B object, which contains a C object, which in turn contains a D object. I need to access the "name" property of the D object starting from the A object.
Currently, I'm doing it like this:

Код: Выделить всё

a.getB().getC().getD().getName();
I can get the "name" value this way, but I wonder if there is a better way.
Any examples or recommendations would be greatly appreciated.


Источник: https://stackoverflow.com/questions/781 ... -clean-way

Вернуться в «JAVA»