我想扩展ArrayList 类如下面的示例所示,我仅添加了一个属性(TypeFactory)。public class ElementList<E> extends ArrayList<E>{ // Attribute private TypeFactory typeFactory; // Getter/Setter public TypeFactory getTypeFactory() { return typeFactory; } public void setTypeFactory(TypeFactory typeFactory) { this.typeFactory = typeFactory; } // Constructor public ElementList(TypeFactory typeFactory) { super(); this.typeFactory = typeFactory; }}我的问题是在创建新的ElementList对象后,我的IDE(在我的情况下为IntelliJ)找不到getTypeFactory()getter方法,并以红色文本显示(作为错误)。List<Element> stockOfTire = new ElementList<Element>(TypeFactory.Tire);stockOfTire.getTypeFactory();我的申报书有问题吗? (adsbygoogle = window.adsbygoogle || []).push({}); 最佳答案 因为List<Element>不具有这种功能,所以只有ElementList<Element>具有。将您的代码更改为:ElementList<Element> stockOfTire = new ElementList<Element>(TypeFactory.Tire);stockOfTire.getTypeFactory(); (adsbygoogle = window.adsbygoogle || []).push({});
08-03 17:44