Suppose I have these two classes, one of which extends the rest
public class Bar{ public void foo(){ } } public class FooBar extends Bar { @Override public void foo(){ super.foo();
What I want to do is warn the user about calling the superclass method foo if he does not have an override method, is this possible?
Or is there a way to find out, using reflection, that a method that overrides the method of its superclass calls the original method if I pass the class type to super?
eg:
public abstract class Bar{ public Bar(Class<? extends Bar> cls){ Object instance = getInstance(); if (!instance.getClass().equals(cls)) { throw new EntityException("The instance given does not match the class given."); }
Maybe even an annotation that I can apply to the super method, so it shows that it needs to be called?
EDIT
Note that this is not a superclass that should call the foo method, it will be someone calling the foo method of the subclass, for example, the database method close
I would even be pleased that the method is "un-overrideable" if it came to it, but still would like to give it a special message.
Edit 2
Here is what I wanted along the way:

But it would be nice to have the above or even give them a custom message to do something else, like Cannot override the final method from Bar, please call it from your implementation of the method instead
java reflection
Fabiancook
source share