Java Casting ArrayIterator<Object>
queryMe方法返回一个ArrayIterator<;我>;。queryYou方法返回一个ArrayIterator<;你>
public ArrayIterator<Object> query(String table, String field, String criterion)
{
ArrayIterator<Object> result = null;
if (table.equals("MyTable")
{
result = MyTable.queryMe(field, criterion);
}
else if (table.equals("YourTable")
{
result = YourTable.queryYou(field, criterion);
}
return result;
}
我收到一个错误,上面写着
ArrayIterator<Me> and ArrayIterator<Java.lang.object> are incompatible types.
有什么建议吗
# 1 楼答案
你不能强制转换它,因为
ArrayIterator<Me>
不是ArrayIterator<Java.lang.object>
的子类型。事实上,这两种类型是不相关的Find more explanation