[color=blue][size=xx-large]什么是Nested Class[/size][/color]
在另一个Java类中定义的Java类,Inner Class(Non-static Nested Class)、Static Nested Class、Local Class、Anonymous Class和Lambda Expression都属于Nested Class。
[color=blue][size=x-large]Static Nested Class[/size][/color]
[list]
[*]有static关键字修饰的Nested Class。
[*]可以直接访问类的其他static成员。
[*]不能访问对象成员。
[/list]
[color=blue][size=x-large]Inner Class[/size][/color]
[list]
[*]没有static关键字修饰的Nested Class,即Non-static Nested Class。
[*]所有Inner Class(包括Local Class、Anonymous Classes)可以直接访问对象成员。
[/list]
[color=blue][size=x-large]Local Class[/size][/color]
[list]
[*]在某个代码块中(例如某个方法内部)定义的类。
[*]所有的Local Class(包括Anonymous Classes)除了可以直接访问对象成员之外,还可以访问final的local variable。
关于这一feature的实现:[url]http://hllvm.group.iteye.com/group/topic/38194[/url]
[/list]
[color=blue][size=x-large]Anonymous Classes[/size][/color]
[list]
[*]没有类名,只被用到一次的Local Class
[/list]
[color=blue][size=x-large]Lambda Expression[/size][/color]
由Java8开始支持,aims to support programming in a multicore environment by adding closures and related features to the Java language.
详见:[url]http://docs.oracle.com/javase/tutorial/java/javaOO/lambdaexpressions.html[/url]
在另一个Java类中定义的Java类,Inner Class(Non-static Nested Class)、Static Nested Class、Local Class、Anonymous Class和Lambda Expression都属于Nested Class。
[color=blue][size=x-large]Static Nested Class[/size][/color]
[list]
[*]有static关键字修饰的Nested Class。
[*]可以直接访问类的其他static成员。
[*]不能访问对象成员。
[/list]
[color=blue][size=x-large]Inner Class[/size][/color]
[list]
[*]没有static关键字修饰的Nested Class,即Non-static Nested Class。
[*]所有Inner Class(包括Local Class、Anonymous Classes)可以直接访问对象成员。
[/list]
[color=blue][size=x-large]Local Class[/size][/color]
[list]
[*]在某个代码块中(例如某个方法内部)定义的类。
[*]所有的Local Class(包括Anonymous Classes)除了可以直接访问对象成员之外,还可以访问final的local variable。
关于这一feature的实现:[url]http://hllvm.group.iteye.com/group/topic/38194[/url]
[/list]
[color=blue][size=x-large]Anonymous Classes[/size][/color]
[list]
[*]没有类名,只被用到一次的Local Class
[/list]
[color=blue][size=x-large]Lambda Expression[/size][/color]
由Java8开始支持,aims to support programming in a multicore environment by adding closures and related features to the Java language.
详见:[url]http://docs.oracle.com/javase/tutorial/java/javaOO/lambdaexpressions.html[/url]