This commit is contained in:
wu 2024-10-24 11:59:13 +08:00
parent 9558107356
commit 7f461fc7de

View File

@ -266,15 +266,11 @@ System.out.println(append.convert("Hello", "Lambda")); // 输出 "Hello, Lambda"
```java
// 假设我们有一个简单的类
class Example {
private final int value;
public Example(int value) {
this.value = value;
public Example() {
}
@Override
public String toString() {
return "Example{" + "value=" + value + '}';
public String doSomething() {
return "Example do something“;
}
}
@ -286,13 +282,11 @@ interface ExampleSupplier {
public class Main {
public static void main(String[] args) {
// 使用lambda表达式和构造函数引用创建ExampleSupplier实例
ExampleSupplier supplier = () -> new Example(42);
ExampleSupplier supplier = Example::new;
// 使用ExampleSupplier实例来创建Example对象
Example example = supplier.get();
// 输出结果
System.out.println(example);
example.doSomething();
}
}
```