Predicate和Consumer接口– Java 8中java.util.function包下的接口java
public
static
Student updateStudentFee(Student student, Predicate<Student> predicate,
express
Consumer<Student> consumer){ide
//Use the predicate to decide when to update the discount.spa
if
( predicate.test(student)){
code
consumer.accept(student);
orm
接口 return
student;
ci}
string}
itpublic
static
void
main(String[] args) {
Student student1 =
new
Student(
"Ashok"
,
"Kumar"
,
9.5
);
tudent1 = updateStudentFee(student1,
//Lambda expression for Predicate interface
student -> student.grade >
8.5
,
//Lambda expression for Consumer inerface
student -> student.feeDiscount =
30.0
);