I have an interface
public interface LdapConnectionFactory {
LdapConnectionWrapper getConnectionWrapper() throws LDAPException;
}
and the implementation class LdapConnectionFactoryImpl
which implements the getConnectionWrapper()
method.
public class LdapConnectionFactoryImpl implements LdapConnectionFactory {
...
public LdapConnectionWrapper getConnectionWrapper() throws LDAPException {
...
}
}
When I ran checkstyle, it flags the getConnectionWrapper()
as error - Method 'getConnectionWrapper' is not designed for extension - needs to be abstract, final or empty.
Any advice? Thanks.
Checkstyle
is saying that either the class or method should be marked as final
since it is non-empty and therefore not designed for being overridden.
This is one of the rules of Checkstyle
that I don't personally agree with and tend to disable.
Checkstyle is throwing this message because you have provided an implementation but have not marked the method as final. You can disable this check via Eclipse Preferences and editing your Checkstyle configuration. The specific rule is Class Design > Design for Extension.
The description for the check is pretty decent, and is as follows:
Checks that classes are designed for extension. More specifically, it enforces a programming style where superclasses provide empty "hooks" that can be implemented by subclasses. The exact rule is that nonprivate, nonstatic methods of classes that can be subclassed must either be
- abstract or
- final or
- have an empty implementation
Rationale: This API design style protects superclasses against beeing broken by subclasses. The downside is that subclasses are limited in their flexibility, in particular they cannot prevent execution of code in the superclass, but that also means that subclasses cannot corrupt the state of the superclass by forgetting to call the super method.
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