그래서이 흥미로운 문제가 있습니다 ... 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입니다.
편집 : 대지 설명 :
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 '를'속성 '으로 변경 하시겠습니까? –
Shark