我在某些课程中说ClassCastException
和界面MarketplaceBasicProductList
课程时,我正在获得IMarketplaceProductList
- 为什么?
public static IMarketplaceProductList createMarketplaceBasicProductList(Table basicInfoTable) {
ArrayList list = new ArrayList();
if (basicInfoTable != null) {
for (int i = 1; i <= basicInfoTable.getRowCount(); i++) {
IMarketplaceBasicProduct product = createMarketplaceBasicProduct(basicInfoTable, i);
list.add(product);
}
}
return (IMarketplaceProductList) new MarketplaceBasicProductList(list);
}
1
public interface IMarketplaceProductList extends Serializable {
public int getProductCount();
public IMarketplaceBasicProduct getProductMKPInfo(int index);
}
public class MarketplaceBasicProductList extends AbstractProductList
{..............
public abstract class AbstractProductList implements IProductList
{.............
我还需要在这里添加实现IMarketplaceProductList吗?
public interface IMarketplaceBasicProduct extends Serializable
{...获取MarketplaceBasicProduct函数的方法.. 5。public class MarketplaceBasicProduct extends BasicProduct implements IMarketplaceBasicProduct, IGenericProductFields {
public class BasicProduct extends AbstractProduct {
7。public abstract class AbstractProduct extends AbstractGenericProduct implements IProduct {
我还需要在这里添加实现IMarketplaceBasicProduct
吗?
答案 0 :(得分:2)
由于您的课程ClassCastException
不是 MarketplaceBasicProductList
,您将获得IMarketplaceProductList
。
MarketplaceBasicProductList extends AbstractProductList implements IMarketplaceProductList
从您拥有的结构来看,AbstractProductList
对于每种类型的产品列表都是通用的,IMarketplaceProductList
将包含MarketplaceBasicProductList
的特定方法,因此只有MarketplaceBasicProductList
将实施IMarketplaceProductList
此外,我觉得IMarketplaceProductList
将在IProductList
之上和之上提供功能,因此IMarketplaceProductList
定义应该是这样的:
public interface IMarketplaceProductList extends IProductList {
}