Can we use stub methods for implementing interfaces ? i.e., suppose I get a message that says I must implement ServletRequestAttributeListener and HttpSessionListener - what do I need to do? Can I simply put the method signature, and use dummy values?
I understand that you're in general talking about those XxxListener interfaces in the Servlet API.
If you're not interested in hooking on the event, just do nothing. Leave the method body empty. If necesary, add a comment like NOOP (no operation) to suppress the IDE "empty body" warning.
@Override
public void sessionDestroyed(HttpSessionEvent event) {
// NOOP.
}
For other interfaces, it depends on their contract. I'd read their javadocs to be sure.
Yes you can as long as you understand the main drawback of this: the contract provided by the interface will not be satisfied by your class. This may be a problem if others end up using your code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With