What i am trying to do: get the value of the a reflected field named "f3" with the type "K". I would like to be able to use the value of f3 to reflect fields from within it. (edit)f3 is inside class b which is from a .jar file. (edit)
All methods of getting the value that i try give the error: can not set K field f3 to java.lang.Class.
Question: How can i get the value of the field f3 (which has the type K) on the class b (which is a class loaded from an external jar) ?
The following code throws an IllegalArgumentException :
Class instance = loadClass("b"); // simplified for readability
Field fieldf3 = instance.getDeclaredField("f3");
fieldf3.setAccessible(true);
Object value = fieldf3.get(instance); //exception on this line.
StackTrace :
java.lang.IllegalArgumentException: Can not set K field b.f3 to java.lang.Class
at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:167)
at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:171)
at sun.reflect.UnsafeFieldAccessorImpl.ensureObj(UnsafeFieldAccessorImpl.java:58)
at sun.reflect.UnsafeObjectFieldAccessorImpl.get(UnsafeObjectFieldAccessorImpl.java:36)
at java.lang.reflect.Field.get(Field.java:387)