JSL的内容比较多,比较细,先以各版本语言特性的主线进行选择性学习:
J2SE各版本新引入的语言特性如下:
1.1 J2SE 1.4
- Assertion Facility
1.2 J2SE 5.0
- Generics(泛型)
- Enhanced for Loop
- Autoboxing/Unboxing
- Typesafe Enums
- Varargs
- Static Import
- Annotations
1.3 J2SE 6
无
1.4 J2SE 7
- Binary Literals
- Underscores in Numeric Literals
- Strings in switch Statements
- Type Inference for Generic Instance Creation
- Improved Compiler Warnings and Errors When Using Non-Reifiable Formal Parameters with Varargs Methods
- The try-with-resources Statement
- Catching Multiple Exception Types and Rethrowing Exceptions with Improved Type Checking
1.5 J2SE 8
- Lambda Expressions
- Improved Type Inference
- Annotations on Java Types
- Repeating Annotations
- Method Parameter Reflection
1.6 J2SE 9
- Java Platform Module System
- New Version-String Scheme
一、Generics(泛型)
涉及章节:8.1.2、8.4.4、8.8.4、9.1.2
8.1.2 泛型类和类型参数
如果一个类声明了一个或多个类型变量(type variables,用于描述类型,泛指任意类型或相关一类类型,用大写字母标示,如K、V、E等),那么这个类就是一个泛型类。
这些类型变量也称之为类的类型参数(type parameters)。类型参数紧接着类名,并用尖括号分隔,如<T,K,V>。
8.4.4 泛型方法
如果一个方法声明了一个或多个类型变量,那么这个方法就是一个泛型方法。
这些类型变量称之为方法的类型参数。
8.8.4 泛型构造函数
如果一个构造行数声明了一个或多个类型变量,那么这个构造行数就是一个泛型构造函数。
这些类型变量称之为构造函数的类型参数。
9.1.2 泛型接口和类型参数
如果一个接口声明了一个或多个类型变量,那么这个接口就是一个泛型接口。
这些类型变量称之为接口的类型参数。类型参数紧接着类名,用尖括号分隔,如<K,V,T>。
二、Annotations(注解)
涉及章节:9.6、9.7、13.5.7
9.6 注解类型
注解类型声明指定了一个新的注解类型,注解类型是一种特殊的接口(interface)。为了区分注解类型的声明与普通接口声明,关键字interface之前增加一个@符号。
9.6.1 注解类型元素
9.6.2 注解类型元素的默认值
9.6.3 可重复的注解类型
9.6.4 预定义的注解类型
@Target
package java.lang.annotation;
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.ANNOTATION_TYPE)
public @interface Target {
/**
* Returns an array of the kinds of elements an annotation type
* can be applied to.
* @return an array of the kinds of elements an annotation type
* can be applied to
*/
ElementType[] value();
}
@Retention
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.ANNOTATION_TYPE)
public @interface Retention {
/**
* Returns the retention policy.
* @return the retention policy
*/
RetentionPolicy value();
}
@Inherited
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.ANNOTATION_TYPE)
public @interface Inherited {
}
@Override
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.SOURCE)
public @interface Override {
}
@SuppressWarnings
@Target({TYPE, FIELD, METHOD, PARAMETER, CONSTRUCTOR, LOCAL_VARIABLE})
@Retention(RetentionPolicy.SOURCE)
public @interface SuppressWarnings {
String[] value();
}
@Deprecated
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target(value={CONSTRUCTOR, FIELD, LOCAL_VARIABLE, METHOD, PACKAGE, PARAMETER, TYPE})
public @interface Deprecated {
}
@SafeVarargs
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.CONSTRUCTOR, ElementType.METHOD})
public @interface SafeVarargs {}
@Repeatable
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.ANNOTATION_TYPE)
public @interface Repeatable {
/**
* Indicates the <em>containing annotation type</em> for the
* repeatable annotation type.
* @return the containing annotation type
*/
Class<? extends Annotation> value();
}
@FunctionalInterface
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface FunctionalInterface {}
9.7 注解
Annotation:
NormalAnnotation
MarkerAnnotation
SingleElementAnnotation
9.7.1 普通注解
9.7.2 Marker Annotations
9.7.3 单元素注解
9.7.4 什么地方会出现注解?
9.7.5 同一个类型的多个注解
13.5.7 注解类型的发展
三、静态导入(static import)
相关章节:7.5.3、7.5.4
四、类型接口
相关章节:18
五、lambda表达式
相关章节:15.13、15.27
15.13 方法引用表达式
15.27 Lambda表达式
Lambda表达式就像一个方法一样,它提供了形式参数列表和主体
LambdaExpression:
LambdaParameters -> LambdaBody
Lambda表达式通常是一个poly expressions。
Lambda表达式只能出现在以下三个地方:
- 赋值上下文
- 调用上下文
- 转换上下文
15.27.1 Lambda参数
lambda表达式的形式参数要么是声明的类型,要么是推断的类型。这些参数的类型不能混用(不能出现一些参数是声明的类型,另一些参数是推断的类型)。
15.27.2 Lambda主体
15.27.3 Lambda表达式的类型
15.27.4 Lambda表达式的运行时赋值(Run-Time Evaluation of Lambda Expressions)
六、switch语句
14.11 switch语句