S <: T(S 是 T 的子类型)S <: T 且 T <: U ⇒ S <: UC(S) <: C(T)(若 S <: T,且 C 协变)C(T) <: C(S)(若 S <: T,且 C 逆变)class C implements A, B(类实现多个接口)interface I extends A, B(接口继承多个接口)final 类不可被继承(如 final class Circle)List<? extends T>(协变,允许读取)List<? super T>(逆变,允许写入)A.<String>contains(strArr, "hello")T[] arr = (T[]) new Object[size])class Pair<S extends Comparable<S>, T>(类型参数边界)class A extends B implements Comparable<A>IllegalArgumentException(参数不合法)class MyException extends IllegalArgumentExceptiontry {
// 可能抛出异常的代码
} catch (IllegalArgumentException e) {
// 处理特定异常
} finally {
// 始终执行
}
throws 声明:public Circle(Point c, double r) throws IllegalArgumentException@FunctionalInterface 标记(如 Transformer<T, R>)Transformer<Integer, Integer> square = x -> x * x;A::foo(静态方法)或 aInstance::bar(实例方法)x -> y -> x + ymap 与 flatMap:list.map(x -> x + 1).flatMap(x -> List.of(x, x * 2));
new Thread(() -> { ... }).start();isAlive() 检查线程是否存活synchronized 关键字(同步方法或代码块)CompletableFuture.supplyAsync(() -> 42)
.thenApply(x -> x * 2)
.thenAccept(System.out::println);
.handle((result, ex) -> ex != null ? fallback : result)Stream.of(1, 2, 3) 或 IntStream.iterate(0, i -> i + 2)filter, map, sorted, distinctcollect, reduce, forEach.parallel()ConcurrentModificationException)final 字段与防御性拷贝(如 Circle 类的 final private Point c)Circle.createCircle(Point c, double r)ClosedCircle 扩展 Circle)Lazy<T> 类:仅在首次调用 get() 时计算值public, protected, private, 默认(包私有)@Override(重写方法)@SuppressWarnings("unchecked")(抑制泛型警告)✅ 复习建议:结合代码示例理解泛型型变、多线程同步机制,以及流操作的链式调用。注意 final 和函数式接口的实际应用场景。