mardi 23 janvier 2018

Java reflection giving wrong concrete type at runtime

I'm trying to get the field value of an object using java.lang.reflect.Field#get. Moreover, I'd like to get the concrete type of a field of type interface java.util.List.

This is the code I'm currently using:

Field field = getField(klass, fieldName); 
//getField returns a field of type interface java.util.List
field.setAccessible(true);
Object result = field.get(target);

The problem is that instead of obtaining an Object instance of class java.util.Arrays$ArrayList (I'm 100% sure that this is the concrete type), I'm getting an instance of class java.util.ArrayList.

Am I doing something wrong? Thanks in advance.





Aucun commentaire:

Enregistrer un commentaire