local class的scope是local,所以在方法外不可见,这个三楼说过了。
这里有总结:
A class defined within another class is called a nested class. Like other members of a class, a nested class can be declared static or not. A nonstatic nested class is called an inner class. An instance of an inner class can exist only within an instance of its enclosing class and has access to its enclosing class's members even if they are declared private.
http://docs.oracle.com/javase/tutorial/java/javaOO/summarynested.html
但我觉得红色字体部分的说法还是不严谨,在静态上下文中声明的inner class还是不是必须需要instance of its enclosing class呢?比如以下情况:
class Outter {
static void function() {
class Inner {
void show() {
System.out.println("hahaha");
}
}
new Inner().show();
}
}
-
这种情况怎么解释呢?希望能找到不是不严谨的说法。
However, not all inner classes have enclosing instances; inner classes in static contexts, like an anonymous class used in a static initializer block, do not.
https://blogs.oracle.com/darcy/entry/nested_inner_member_and_top
补充:还是严谨的,can exist