Я получаю предупреждение компилятора:
предупреждение: [unchecked] unchecked вызов setView (V) в качестве члена необработанного типа AbstractPresenter
this.presenter.setView(this);
где V - переменная типа:
V расширяет AbstractView, объявленный в классе AbstractPresenter
Код класса AbstractPresenter
следующий:
public abstract class AbstractPresenter<V extends AbstractView, M>
implements Presenter<V, M> {
private M model;
private V view;
@Override
public final V getView() {
return this.view;
}
public final void setView(V view) {
if (view == null) {
throw new NullPointerException("view cannot be null.");
}
if (this.view != null) {
throw new IllegalStateException("View has already been set.");
}
this.view = view;
}
@Override
public final M getModel() {
return this.model;
}
protected final void setModel(M model) {
if (model == null) {
throw new NullPointerException("model cannot be null.");
}
this.model = model;
}
}
Метод setView
вызывается в классе AbstractView
ниже:
public abstract class AbstractView<P extends AbstractPresenter> extends
UserControl {
private final P presenter;
public AbstractView(P presenter) {
this.presenter = presenter;
this.initialisePresenter();
}
private void initialisePresenter() {
if (this.presenter == null){
throw new IllegalStateException();
}
this.presenter.setView(this); //This is the call that raises the warning
}
protected P getPresenter() {
return this.presenter;
}
}
Я искал вопросы от других участников относительно того же предупреждения и пытался адаптировать решения к моей проблеме, но это не сработало.
Я не понимаю, почему предупреждение возникает, поскольку тип V
принудительно объявляется классом AbstractPresenter
:
public abstract class AbstractPresenter<V extends AbstractView, M>
implements Presenter<V, M>
Это просто предупреждение, и я мог бы игнорировать его, но я хотел бы понять, почему это происходит, и я хочу, чтобы мой код был как можно более чистым.