3
I have the following expression:
final String idStatusAutorizada = ...; // valor constante
return pendencias.stream()
.map(TipoBlocCarga::getIdStatus)
.anyMatch(idStatusPendencia -> !idStatusAutorizada.equals(idStatusPendencia));
But the latter lambda is not satisfying me aesthetically. I would like to turn into some kind of method reference. Another alternative that I don’t like is to declare a variable with the predicate of idStatusAutorizada::equals
and pass the method to the function of that predicate with negate()
, but I must say that I do not yet seem sufficiently elegant:
final String idStatusAutorizada = ...; // valor constante
Predicate<String> equalsAutorizada = idStatusAutorizada::equals;
return pendencias.stream()
.map(TipoBlocCarga::getIdStatus)
.anyMatch(equalsAutorizada.negate());
I would find it beautiful if it were possible to do
idStatusAutorizada::equals.negate()
, but Java 8 does not allow this. I don’t know if this has changed in the latest versions, but I can’t change the version of Java in my code because of the platforms on which the code will be executed.
So, my question: is it possible to make a predicate of equality in Java?
It cannot be said that Java has not been striving to evolve xD. This last one even without Java 11 was great at readability level.
– Isac