我有一个返回类类型的方法,它工作正常。
问题是......我收到一些编译警告,表明未经检查的转换。
以下是我收到的警告信息:
Warning: java: getAjaxEventPayloadClass() in <anonymous com.iyotbihagay.wicket.panel.requestpage.resultlist.ResultList2$7> implements <P>getAjaxEventPayloadClass() in com.iyotbihagay.wicket.panel.paging.Paging.Support
return type requires unchecked conversion from java.lang.Class<com.iyotbihagay.wicket.support.RefreshSearchResultEventPayload> to java.lang.Class<P>
即使我使用@SuppressWarnings("unchecked")
我仍然无法摆脱编译警告。
以下是一些指向警告的代码:
结果列表2.java
public class ResultList2 {
...
private Component createPaging() {
return new Paging("paging", getRequestPageContext(), new Paging.Support() {
@Override
public void switchPage(AjaxRequestTarget target, int targetPageNum) {
getRequestPageContext().switchPage(target, targetPageNum);
}
@Override
public int getTotalNum() {
return getSearchResult().getTotalNum();
}
@Override
public int getPageSize() {
return getSearchResult().getPageSize();
}
@Override
public int getLastPageNum() {
return getSearchResult().getLastPageNum();
}
@Override
public int getCurrentPageNum() {
return getSearchResult().getCurrentPageNum();
}
@SuppressWarnings("unchecked")
@Override
public Class<RefreshSearchResultEventPayload> getAjaxEventPayloadClass() {
return RefreshSearchResultEventPayload.class;
}
@Override
public void decorateAjaxAttributes(AjaxRequestAttributes attributes, String pageNumMarkupId) {
decorateAjaxRefreshSearchResult(attributes, pageNumMarkupId);
}
});
}
...
}
支持.java
public static interface Support extends Serializable {
...
<P extends AjaxEventPayload> Class<P> getAjaxEventPayloadClass();
...
}
分页.java
public class Paging {
...
private Support m_support;
...
@Override
public void onEvent(IEvent<?> event) {
super.onEvent(event);
WicketUtil.onEvent(event, m_support.getAjaxEventPayloadClass(), new AjaxEventHandler<AjaxEventPayload>() {
@Override
public void onEvent(IEvent<?> event, AjaxRequestTarget target, AjaxEventPayload paymentLoad) {
m_firstPageNumModel.detach();
m_previousPageNumModel.detach();
m_nextPageNumModel.detach();
m_lastPageNumModel.detach();
target.add(m_container);
}
});
}
...
}
WicketUtil.java
public class WicketUtil {
...
public static <P extends AjaxEventPayload> void onEvent(IEvent<?> event, Class<P> targetPayload, AjaxEventHandler<P> handler) {
if (event.getPayload() != null) {
if (targetPayload.isAssignableFrom(event.getPayload().getClass())) {
P p = (AjaxEventPayload)event.getPayload();
handler.onEvent(event, p.getTarget(), p);
}
}
}
...
}
m_support.getAjaxEventPayloadClass()
被调用/传递WicketUtil.onEvent()
...特别是在第二个参数上。
RefreshSearchResultEventPayload
只是扩展的类之一,AjaxEventPayload
还有其他类扩展AjaxEventPayload
并传递给WicketUtil.onEvent()
.