Java 我在使用类和对象时出错
我想通过show()方法将对象的元素作为数组返回,但还有一个错误:Java 我在使用类和对象时出错,java,class,object,Java,Class,Object,我想通过show()方法将对象的元素作为数组返回,但还有一个错误: error: cannot find symbol this.insert(set.NewSet[j]); ^ symbol: variable NewSet location: variable set of type ASet []仅在数组中工作,而不在集合中工作(而且集合未排序,没有第一个或第二个元素的概念,如果需要排序,请使用排序集)。您可以迭代
error: cannot find symbol
this.insert(set.NewSet[j]);
^
symbol: variable NewSet
location: variable set of type ASet
[]
仅在数组中工作,而不在集合中工作(而且集合
未排序,没有第一个或第二个元素的概念,如果需要排序,请使用排序集
)。您可以迭代集合以获取其值。NewSet
是在set
类中定义的,而不是在ASet
类中定义的。编译器不知道ASet
的所有实现是否都会有该字段(不是说您可以在接口中定义成员变量)。接口ASet
不太可能也定义了一个名为NewSet
的变量(常量)。也许您想将set
声明为set
?我建议不要将类命名为“set”,它是标准集合接口之一。
error: cannot find symbol
this.insert(set.NewSet[j]);
^
symbol: variable NewSet
location: variable set of type ASet
error: cannot find symbol
return Array.from(this.NewSet);
^
symbol: method from(Integer[])
location: class Array