vendredi 4 août 2023

How to access and process Fields of Type Map in a Class using Java Reflection

I am trying to access and print all Fields of below mentioned Class (MainClass) using Java Reflection

public class MainClass{
  private int aInt;
  private char aChar;
  private boolean aBoolean;
  private Map<Integer, SubClass> subClassMap;

/*** Setters & Getters ***/

}

public class SubClass{
  private long aLong;
  private float aFloat;
  private double aDouble;

/*** Setters & Getters ***/
}

It is able to access all Fields and print the details like Type, Name etc using

(new MainClass()).getClass().getDeclaredFields()

But how I can access and print the details like Key and Value part of Field subClassMap of Type Map (Map<Integer, SubClass>).





Aucun commentaire:

Enregistrer un commentaire