mardi 30 juillet 2019

How to get class from the method implemented in abstract class

Let's say I have an Abstract class as follows:

public abstract class Abstract{
   public void mymethod() {

   }
}

And a class implementing it:

public class Implementation extends Abstract {

}

I'm calling the mymethod from Implementation class and and inspecting it:

method.getDeclaringClass()
            .getDeclaredConstructor().newInstance();

This fails since the Declaring class is abstract so it can't be instantiated. I'm trying to figure out how to retrieve the calling class instead.





Aucun commentaire:

Enregistrer un commentaire