In an example code like this, my IDE changed my code from using an anonymous class to return a lambda. That's cool but how does it work?
public static Specification<User> getUsersByFirstNameSpec(String name) {
return new Specification<User>() {
@Override
public Predicate toPredicate(Root<User> root,
CriteriaQuery<?> query,
CriteriaBuilder criteriaBuilder) {
Predicate equalPredicate = criteriaBuilder.like(
criteriaBuilder.upper(root.get("firstName")),
name.toUpperCase());
return equalPredicate;
}
};
}
How does java know the type of the 3 parameters?
public static Specification<User> getUsersByLastNameSpec(String name) {
return (Specification<User>) (root, query, criteriaBuilder) -> {
Predicate equalPredicate = criteriaBuilder.like(
criteriaBuilder.upper(root.get("lastName")),
name.toUpperCase());
return equalPredicate;
};
}