Possible Duplicate:
Reduce visibility when implementing interface in Java
I must be missing something obvious, but i am getting:
Cannot reduce the visibility of the inherited method
And I don’t see how. This is my interface:
interface QueryBuilderPart {
StringBuilder toStringBuilder();
}
And this is my implementation:
public class Stupid implements QueryBuilderPart {
@Override
StringBuilder toStringBuilder() {
return null;
}
}
Both the class and the implementation are in the same package. Any Ideas?
By default interface’s method is
public, but you reduce it to default visibility, which is package level visibility.So the following two block of code are the same:
Note that interface’s method is
abstractas wellSo you should do as following: