Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/399.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 我在使用类和对象时出错_Java_Class_Object - Fatal编程技术网

Java 我在使用类和对象时出错

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 []仅在数组中工作,而不在集合中工作(而且集合未排序,没有第一个或第二个元素的概念,如果需要排序,请使用排序集)。您可以迭代

我想通过show()方法将对象的元素作为数组返回,但还有一个错误:

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