jeudi 23 septembre 2021

Get types of all instance variables in Java

I have a class named Attributes, which has some instance variables as listed below:

public class Attributes {
   protected A variable1;
   protected B variable2;
   protected C variables3;
   
   /*
     Getters and Setters of each method.
  */
   
}

I want the list of all instance variables' types present in the class.

The output: [A,B,C]

This contains all possible dataTypes present in this class.

Can someone please suggest a way?

NOTE: I've seen reflection, but I think it is useful only if we have filled the values for these variables and we want to fetch the values and names of those variables, not the types.





Aucun commentaire:

Enregistrer un commentaire