Bootstrap

关于“No enclosing instance of type * is accessible. Must qualify the allocation with an enclo……”的总结与思考

报错的完整信息:

No enclosing instance of type OutterClass is accessible. Must qualify the allocation with an enclosing instance of type OutterClass (e.g. x.new A() where x is an instance of OutterClass).

错误的出现背景:

Java

在类中添加内部类,并在main函数中通过语句:

OutterClass.InnerClass innerClass = new OutterClass.InnerClass();

试图构造内部类对象时出现。

完整结构如下:

public class OutterClass {

	class InnerClass {
		
		void print() {
			System.out.println("this is innerClass");
		}
		
	}
	
	public static void main(String[] args) {
		OutterClass.InnerClass innerClass = new OutterClass.InnerClass();
		innerClass.print();
	}
	
}

思考:

悦读

道可道,非常道;名可名,非常名。 无名,天地之始,有名,万物之母。 故常无欲,以观其妙,常有欲,以观其徼。 此两者,同出而异名,同谓之玄,玄之又玄,众妙之门。

;