I want that when a child class overrides a method in a parent class, the super.method() is called in that child method.
Is there any way to check this at compile time?
If not, how would I go about throwing a runtime exception when this happens?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
There’s no way to require this directly. What you can do, however, is something like:
This provides an internal interface-point that subclasses can use to add custom behavior to the public
myExposedInterface()method, while ensuring that the superclass behavior is always executed no matter what the subclass does.