Réflexion champ privé de la super classe
Bonjour,
Depuis une classe fille j'essaye d'accèder a un champ privé de la classe mère
Code:
1 2 3 4 5 6 7 8 9 10
|
Properties conn = null;
Class c = null;
c = this.getClass();
Class parent = c.getSuperclass();
Field f = parent.getDeclaredField("mProperties");
f.setAccessible(true)
System.out.println(f.getType()) ; // renvoi bien java.util.Properties;
Object test = f.get(parent); //ici erreur
//avec conn = (Properties) f.get(parent); erreur aussi... |
j'ai l'exception suivante :
Citation:
@exception IllegalArgumentException if the specified object is not
* an instance of the class or interface declaring the
* underlying field (or a subclass or implementor
* thereof), or if the field value cannot be
* converted to the type <code>int</code> by a
* widening conversion.
Merci de votre aide