vendredi 2 avril 2021

Java chained reflection

I have this chained method call

Integer.parseInt(A.get().getC().getD().toString());

I need to make this with reflection. I know that I can use Class.forName(String class) and then invoke methods, but how do I save method results so I can call that chain.

Classes:

public class A
{
       public static B get() { return new B(); }
}

public class B
{
     public C getC() { return new C();}
}

public class C
{
      public C getD() { return new D();}
}




Aucun commentaire:

Enregistrer un commentaire