Give a nested class definition
class A {
B b;
public B getB() {
return b;
}
}
class B {
ArrayList<C> list;
public getListC() {
return list;
}
}
class C {
D d;
public D getD() {
return d;
}
}
class D {
E e;
public E getE() {
return e;
}
}
Now let's say that I have an Instance of Class A and I want to get access to an instance of E through A's instance like following
E someMethod(A a) {
if (a == null
|| a.getB() == null
|| a.getB().getListC() == null
|| a.getB().getList().isEmpty()
|| a.getB().getList().get(0) == null
|| a.getB().getList().get(0).getD() == null) {
return null;
}
return a.getB().getList().get(0).getD().getE();
}
Now I want to know if there is a way to automatically genererate the above code using Annotation or some other tool so that I don't have to repeaditly write such a code. I should only be doing following
E someMethod(A a) {
@AwesomeAnnotation(a.getB().getList().get(0).getD().getE());
}