この興味深い問題があります... ArrayListで拡張されたListから取得されたオブジェクトのメソッドにアクセスしたいです。ArrayList拡張のキャストオブジェクトにはメソッドがありません
それは次のようになります。私はマークされた行のメソッドにアクセスすることはできませんなぜ
import java.util.ArrayList;
import java.util.Collection;
public class PropertyList<Property> extends ArrayList {
private static final long serialVersionUID = -7854888805136619636L;
PropertyList(){
super();
}
PropertyList(Collection<Property> c){
super(c);
}
boolean containsProperty(PropertyList<Property> pl){
Property asdf = (Property) this.get(4);
System.out.println(asdf.<can't access "Property" methods>); //mark
return false;
}
}
任意のアイデア? 明確にするために、Propertyオブジェクトのメソッドはpublicです。
EDIT: プロパティの説明:
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlValue;
@XmlAccessorType(XmlAccessType.FIELD)
class Property {
@XmlValue
private String property = null;
@XmlAttribute
String state;
@XmlAttribute
String name;
@XmlAttribute
String type;
@XmlAttribute
String value;
Property(){}
Property(String state, String name, String type, String value){
this.state = state;
this.name = name;
this.type = type;
this.value = value;
}
public String getName(){
return name;
}
@Override
public String toString(){
return state + " " + name + " " + type + " " + value;
}
}
'ArrayList'を拡張してはいけませんか?関係なく、あなたは 'Property'のコードも表示できませんか? –
Shark
@Shark確かに。今のところそれは意味をなさない。しかし、 'Property'への明示的なキャストは私にも定義を見せてくれるでしょう:) – jensgram
あなたのクラス宣言は' public class PropertyList extends ArrayList 'となり、 T'を 'Property'に変換する? –
Shark