包含< my reference>的封闭实例是必须的 [英] An enclosing instance that contains <my reference> is required
问题描述
包含的封闭实例是必需的
An enclosing instance that contains is required
下面是代码. positionObj
是我要使用的对象,它给了我上面的错误.
Below is the code. positionObj
is the object that I am trying to use and it is giving me the above error.
不清楚为什么.
package toolBox;
import toolBox.Secretary.positionObj;
public class PositionManagement {
public static HashMap<String, Secretary.positionObj> main(String vArg){
positionObj newPosition=new positionObj();
}
}
推荐答案
您正在尝试使用不带Secretary
实例的非静态内部内部positionObj
类.
非静态内部类必须属于其父类的实例
You're trying to use the non-static inner positionObj
class without an instance of Secretary
for it to belong to.
A non-static inner class must belong to an instance of its parent class
您可能应该将positionObj
更改为普通类或静态内部类.
You should probably change positionObj
to a normal class or a static inner class.
或者,您可以编写someSecretary.new positionObj()
来创建属于someSecretary
实例的内部类的实例.
Alternatively, you can write someSecretary.new positionObj()
to create an instance of the inner class that belongs to the someSecretary
instance.
这篇关于包含< my reference>的封闭实例是必须的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!