jeudi 1 septembre 2016

NoSuchMethodException when using reflection to intantiate protected constructor

This is the first time I using reflection and do not know what mistake I am doing in instantiating the protected constructor. Below is my code to instantiate a constructor of JsonProcessingException.

getDeclaredConstructor is causing NoSuchMethodException, though this exception class has protected constructor with one, two and three parameters.

final Constructor<JsonProcessingException> constructor = 
    JsonProcessingException.class
        .getDeclaredConstructor(Object.class, Object.class);
constructor.setAccessible(true);

My Assumption: I have read that we can instantiate private constructor using reflection so I am assuming proteted can also be instantiated.

Any help is greatly appreciated.





Aucun commentaire:

Enregistrer un commentaire