mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-02-05 08:06:56 +07:00
32 lines
689 B
Java
32 lines
689 B
Java
// "Replace null check with orElseGet(new Person(...))" "true"
|
|
|
|
import java.util.*;
|
|
|
|
public class Main {
|
|
static class Person {
|
|
String name;
|
|
int age;
|
|
|
|
public String getName() {
|
|
return name;
|
|
}
|
|
|
|
public int getAge() {
|
|
return age;
|
|
}
|
|
|
|
public Person(String name, int age) {
|
|
this.name = name;
|
|
this.age = age;
|
|
}
|
|
}
|
|
|
|
public Person work() {
|
|
List<Person> personList = Arrays.asList(
|
|
new Person("Roman", 21),
|
|
new Person("James", 25),
|
|
new Person("Kelly", 12)
|
|
);
|
|
return personList.stream().filter(p -> p.getAge() > 13).max(Comparator.comparingInt(Person::getAge)).orElseGet(() -> new Person("noname", 0));
|
|
}
|
|
} |