Does anyone know how to get the declaring / enclosing class of an abstract class in Java? In this case, I would like to get the anotherClass class from within someClass.
Example:
public class anotherClass extends someClass{
...
}
public abstract class someClass{
...
this.getClass().getEnclosingClass();
}
If you call
this.getClass()in an abstract class it will still return the class of the actual implementation. In your case callingthis.getClass()will returnanotherClass, which is what you want if I am not wrong.