我有一个构建器界面:
@ParametersAreNonnullByDefault
public interface ILoadableBuilder<C extends ILoadable,T extends ILoadableBean> {
public @Nonnull T getState();
public @Nonnull <B extends ILoadableBuilder<C,T>> B setComponentClass(final Class<C> componentClass);
public @Nonnull <B extends ILoadableBuilder<C,T>> B setDriver(final WebDriver driver);
public @Nonnull <B extends ILoadableBuilder<C,T>> B setLoadTimeoutInSeconds(final @Nonnegative int loadTimeoutInSeconds);
public @Nonnull <B extends ILoadableBuilder<C,T>> B setEnumerator(final IEnumeratorBean<? extends IEnumerable<?>,?> enumerator);
}
和这个实现:
@ParametersAreNonnullByDefault
public class LoadableBuilder<C extends ILoadable,T extends ILoadableBean,B extends ILoadableBuilder<C,T>> implements
ILoadableBuilder<C,T> {
private final @Nonnull T componentBean;
private @Nullable IEnumeratorBean<? extends IEnumerable<?>,?> enumerator;
private @Nullable Class<C> componentClass;
public LoadableBuilder(final T componentBean) {
this.componentBean = componentBean;
}
@Override
public final @Nonnull T getState() {
return componentBean;
}
@SuppressWarnings("unchecked")
@Override
public final @Nonnull B setComponentClass(final Class<C> componentClass) {
this.componentClass = componentClass;
return (B)this;
}
@SuppressWarnings("unchecked")
@Override
public final @Nonnull B setDriver(final WebDriver driver) {
getState().setDriver(driver);
return (B)this;
}
@SuppressWarnings("unchecked")
@Override
public final @Nonnull B setLoadTimeoutInSeconds(final @Nonnegative int loadTimeoutInSeconds) {
getState().getLoadTimeoutInSeconds();
return (B)this;
}
@SuppressWarnings("unchecked")
@Override
public @Nonnull B setEnumerator(final IEnumeratorBean<? extends IEnumerable<?>,?> enumerator) {
this.enumerator = enumerator;
return (B)this;
}
public @Nullable Class<C> getComponentClass() {
return componentClass;
}
}
编译器抱怨实现类中的setComponentClass方法和setEnumeratorMethod - 它表示它们不会覆盖接口中的方法,但它不会抱怨任何其他以相同方式实现的方法具有相同的返回值。为什么这两种方法对编译器来说是一个问题,但其他方法不是?
编译器错误:
Error:(16, 8) java: com.someplace.api.ui.LoadableBuilder is not abstract and does not override abstract method <B>setEnumerator(com.someplace.api.ui.IEnumeratorBean<? extends com.someplace.api.dsl.IEnumerable<?>,?>) in com.someplace.api.ui.ILoadableBuilder
Error:(47, 29) java: name clash: setComponentClass(java.lang.Class<C>) in com.someplace.api.ui.LoadableBuilder and <B>setComponentClass(java.lang.Class<C>) in com.someplace.api.ui.ILoadableBuilder have the same erasure, yet neither overrides the other
Error:(46, 5) java: method does not override or implement a method from a supertype
Error:(68, 23) java: name clash: setEnumerator(com.someplace.api.ui.IEnumeratorBean<? extends com.someplace.api.dsl.IEnumerable<?>,?>) in com.someplace.api.ui.LoadableBuilder and <B>setEnumerator(com.someplace.api.ui.IEnumeratorBean<? extends com.someplace.api.dsl.IEnumerable<?>,?>) in com.someplace.api.ui.ILoadableBuilder have the same erasure, yet neither overrides the other
Error:(67, 5) java: method does not override or implement a method from a supertype