From 9eb529af0df836ef05d43a01a2647f0dd56dcd83 Mon Sep 17 00:00:00 2001 From: zeroornull Date: Sat, 15 Mar 2025 02:28:33 +0800 Subject: [PATCH] renamed: "src/interview/java/java\345\237\272\347\241\200.md" -> src/interview/java/java.md --- src/interview/java/{java基础.md => java.md} | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) rename src/interview/java/{java基础.md => java.md} (99%) diff --git a/src/interview/java/java基础.md b/src/interview/java/java.md similarity index 99% rename from src/interview/java/java基础.md rename to src/interview/java/java.md index 0ba5d93..4f10078 100644 --- a/src/interview/java/java基础.md +++ b/src/interview/java/java.md @@ -5158,7 +5158,7 @@ monitor -c 5 demo.MathGame primeFactors ### 6.1 Java 8 特性 -#### [#](https://pdai.tech/md/interview/x-interview.html#什么是函数式编程-lambda表达式)什么是函数式编程?Lambda表达式? +#### 什么是函数式编程?Lambda表达式? - **函数式编程** @@ -5238,11 +5238,12 @@ Supplier personSupplier = Person::new; personSupplier.get(); // new Person ``` -- **断定型接口: Predicate boolean test(T t):有参,但是返回值类型是固定的boolean** -比如: steam().filter()中参数就是Predicate ```java +断定型接口: Predicate boolean test(T t):有参,但是返回值类型是固定的boolean +比如: steam().filter()中参数就是Predicate + Predicate predicate = (s) -> s.length() > 0; predicate.test("foo"); // true @@ -5253,24 +5254,21 @@ Predicate isNull = Objects::isNull; Predicate isEmpty = String::isEmpty; Predicate isNotEmpty = isEmpty.negate(); -``` - -- **函数型接口: Function R apply(T t)有参有返回值的抽象方法**; +函数型接口: Function R apply(T t)有参有返回值的抽象方法; 比如: steam().map() 中参数就是Function;reduce()中参数BinaryOperator (ps: BinaryOperator extends BiFunction) - -```java + Function toInteger = Integer::valueOf; Function backToString = toInteger.andThen(String::valueOf); -backToString.apply("123"); // "123" +backToString.apply("123"); // "123" ``` #### Optional要解决什么问题? 在调用一个方法得到了返回值却不能直接将返回值作为参数去调用别的方法,我们首先要判断这个返回值是否为null,只有在非空的前提下才能将其作为其他方法的参数。Java 8引入了一个新的Optional类:这是一个可以为null的容器对象,如果值存在则isPresent()方法会返回true,调用get()方法会返回该对象。 -#### [#](https://pdai.tech/md/interview/x-interview.html#如何使用optional来解决嵌套对象的判空问题)如何使用Optional来解决嵌套对象的判空问题? +#### 如何使用Optional来解决嵌套对象的判空问题? 假设我们有一个像这样的类层次结构: