mercredi 21 octobre 2015

Java reflection, call method from superClass?

I've seen a lot of examples, and I know what has been discussed. I do everything right, but I receive an error. Why is that? What am i doing wrong?

Class superClass = rootObject.getSuperclass();
      Method addErrorMethod = superClass.getDeclaredMethod("addErrorMessage", ErrorType.class, String.class, String.class, String.class);
      _log.info(addErrorMethod.getName());
      addErrorMethod.invoke(superClass, ErrorType.FIELD, propertyName, message, "");

I get method, but when you call the invoker. I get the following error.

 java.lang.IllegalArgumentException: object is not an instance of declaring class

Thanks.





Aucun commentaire:

Enregistrer un commentaire