我正在编译器警告的构件:编译警告:未经检查调用XXX作为原料类型
警告:作为原料类型AbstractPresenter
的成员[未选中]未经检查调用的setView(V)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>
这只是一个警告,我可以忽略它,但我想理解它为什么会发生,并且希望尽可能清洁我的代码。
代码中的循环引用让我很头疼。为什么观点需要有主持人,为什么主持人需要有观点?你不能把它转换成单向关系吗? – CKing
http://stackoverflow.com/questions/2770321/what-is-a-raw-type-and-why-shouldnt-we-use-it – kervin
@Chetan Kniger和Kervin谢谢你们,现在我知道什么是原始类型,实际上我有一个循环引用,如果我在AbstractPresenter类中声明V的声明,它将转换为循环继承...因此,我需要回到设计部分。我认为视图不需要在这里引用Presenter。 –