java常用函数接口
package com.bilibili;
import java.util.function.Consumer;
import java.util.function.Predicate;
import java.util.function.Supplier;
public class Main {
public static void main(String[] args) {
Supplier<Student> studentSupplier = Student::new;
studentSupplier.get().show();
Student student = new Student();
STUDENT_CONSUMER.andThen(st -> System.out.println("后续操作")).accept(student);
student.score = 70;
boolean b = STUDENT_PREDICATE.and(stu -> stu.score > 90).test(student);
if (!b) {
System.out.println("Java还得多学");
}
}
public static class Student{
int score;
public void show() {
System.out.println("我是学生!!");
}
}
private static final Consumer<Student> STUDENT_CONSUMER = student -> System.out.println(student.toString() + " 好好吃饭!");
private static final Predicate<Student> STUDENT_PREDICATE = student -> student.score >= 60;
}
判空包装类