Skip to content Skip to sidebar Skip to footer

Reflection : Returning Wrong Fields

I was trying to use reflection API to get the fields of a class, I was doing it by passing the the class as an argument to the following method private void someMethod(Class

Solution 1:

You should replace objClass.getClass().getDeclaredFields() with objClass.getDeclaredFields()

objClass is the class object of MyClass

objClass.getClass() is the class object of java.lang.Class

You were getting the declared fields in the class java.lang.Class in your code

Post a Comment for "Reflection : Returning Wrong Fields"