java语言中classes分类



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

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值