Predicate和Consumer接口– Java 8中java.util.function包下的接口
public
static
Student updateStudentFee(Student student, Predicate<Student> predicate,
Consumer<Student> consumer){
//Use the predicate to decide when to update the discount.
if
( predicate.test(student)){
consumer.accept(student);
return
student;
}
}
public
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
);