org.sonar.l10n.java.rules.squid.S1186.html Maven / Gradle / Ivy
The newest version!
There are several reasons for a method not to have a method body:
- It is an unintentional omission, and should be fixed to prevent an unexpected behavior in production.
- It is not yet, or never will be, supported. In this case an
[UnsupportedOperationException|NotSupportedException|IllegalOperationError]
should be thrown.
- The method is an intentionally-blank override. In this case a nested comment should explain the reason for the blank override.
Noncompliant Code Example
public void doSomething() {
}
public void doSomethingElse() {
}
Compliant Solution
@Override
public void doSomething() {
// Do nothing because of X and Y.
}
@Override
public void doSomethingElse() {
throw new UnsupportedOperationException();
}
Exceptions
An abstract class' may have empty methods, in order to provide default implementations for child classes.
public abstract class Animal {
void speak() {
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy