ジェネリック ArrayList 型を拡張する 2 つの型があります。
public class BuyersGuideResponse extends ArrayList<BuyersGuideItem>
{
private void checkStatusAttributes(){ ... }
private void addItems(){ ... }
}
public class CatalogEngineTypeResponse extends ArrayList<CatalogEngineType>
{
private void checkStatusAttributes(){ ... }
private void addItems(){ ... }
}
checkStatusAttributes メソッドは両方の型で同一であるため、抽象的なジェネリック中間型を作成したいと思います。私は現在持っています
public class ArrayListResponse extends ArrayList<Object>
{
// no implementation
}
public class BuyersGuideResponse<BuyersGuideItem> extends ArrayListResponse
{
// implementation unchanged
...
private void addItems()
{
NodeList nodes = doc.getElementsByTagName(CatalogConst.BUYERS_GUIDE_ITEM_NODE_NAME);
for(int i = 0; i < nodes.getLength(); i++)
{
add(new BuyersGuideItem(nodes.item(i)));
}
...
}
...
}
コンパイルすると、次のエラーが生成されます。
BuyersGuideResponse.java:51: error: unexpected type
add(new BuyersGuideItem(nodes.item(i)));
^
required: class
found: type parameter BuyersGuideItem
where BuyersGuideItem is a type-variable
BuyersGuideItem extends Object declared in BuyersGuideItem.java
どこが間違っていますか?