我收到类似于以下内容的编译错误:visitParents(Class<C>)
某些类型的方法不适用于参数(Class<MyClass>)
MyClass 类似于: public class SortableTable<T>{...}
我不喜欢将 SortableTable 的类型参数更改为,<C>
因为许多其他类会受到负面影响,也不能更改 visitParents 以将任何东西Class<C>
作为参数。
任何潜在的解决方案将不胜感激。
谢谢你的建议。我会尽量做到具体而不用代码填充页面。
“visitParents(SortableTable.class, visitor);”行的错误描述:
Component 类型中的方法 visitParents(Class"<"C">", IVisitor"<"C,R">") 不适用于参数 (Class"<"SortableTable">", IVisitor"<"Component,无效">")
public class SelectAllFilterPanel extends Panel{private static final Logger log = Logger.getLogger(CorporateActionsPanel.class);
private static final long serialVersionUID = 1L;
public SelectAllFilterPanel(String id, final IModel<Boolean> model){
super(id);
add(new AjaxCheckBox("selectAll", model){
private static final long serialVersionUID = 1L;
@Override
protected void onUpdate(AjaxRequestTarget target) {
// TODO - do this properly
final AjaxRequestTarget requestTarget = target;
IVisitor<Component, Void> visitor = new IVisitor<Component, Void>(){
@Override
public void component(Component component, IVisit visit) {
SortableTable<?> table = (SortableTable<?>)component;
table.visitChildren(CheckBox.class, new IVisitor<Component, Void>(){
@Override
public void component(Component component, IVisit visit) {
if (!component.getId().equals("selectAll")){
CheckBox checkbox = (CheckBox)component;
if (model.getObject())
checkbox.setModelObject(true);
else
checkbox.setModelObject(false);
requestTarget.add(checkbox);
}
}
});
visit.stop();
}
};
visitParents(SortableTable.class, visitor);
target.add(this);
}
});
}}
排序表类:
public class SortableTable<T> extends DataTable<T, String> { private HeadersToolbar headerToolbar;
@SuppressWarnings("unchecked")
public SortableTable(String tableId, SortableTableDataProvider<T> dataProvider, int maxRows) {
this(tableId, dataProvider.getColumns(), dataProvider, maxRows);
}
@SuppressWarnings("unchecked")
public SortableTable(String tableId, List<IColumnConfig<T, String>> columns, ISortableDataProvider<T, String> dataProvider, int maxRows) {
super(tableId, new java.util.LinkedList<IColumn<T, String>>(columns), dataProvider, maxRows);
addTopToolbar(new NavigationToolbar(this));
addTopToolbar(headerToolbar = new HeadersToolbar(this, dataProvider));
addBottomToolbar(new NoRecordsToolbar(this));
setItemReuseStrategy(ReuseIfModelsEqualStrategy.getInstance());
}
public void setHeaderVisible(boolean visible) {
headerToolbar.setVisibilityAllowed(visible);
}
public boolean isHeaderVisible() {
return headerToolbar.isVisibilityAllowed();
}
@Override
protected Item<T> newRowItem(String id, int index, IModel<T> model)
{
return new OddEvenItem<T>(id, index, model);
}}
visitParent 签名为:
public final <R, C extends MarkupContainer> R visitParents(final Class<C> parentClass,
final IVisitor<C, R> visitor)
{
return visitParents(parentClass, visitor, new AllVisitFilter());
}