Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

266
Vistas
How do I specialize type in functional interface's straight declaration?

Recently I came up with idea to create a following method:

/** Returns a {@link Predicate} which tests whether all its elements match a condition passed as argument. */
private static <T> Predicate<Iterable<T>> allIterableElementsMatch(Predicate<T> elementMatchCondition) { 
    return iterable -> stream(iterable).allMatch(elementMatchCondition);
}

Then I decided to declare Function-field instead of declaring a method above.
The closest uncompilable solution I could provide is this one:

private static final Function<Predicate<?>, Predicate<Iterable<?>>> allIterableElementsMatch = 
    condition -> iterable -> stream(iterable).allMatch(condition);

This is not compiled (IDE highlights condition inside allMatch(...)) because of following reason:

My questions:

  1. Is it implementable in that way or I just misunderstand the concept of using functional interfaces?
  2. Is it possible to specialize some type in Function-s declaration just like in method I've shown?
over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

For the type system, ? from Predicate<?> and ? from Predicate<Iterable<?>> are different things. You can do:

private static <T> Function<Predicate<T>, Predicate<Iterable<T>>> func() {
    return condition -> iterable -> StreamSupport.stream(iterable.spliterator(), false).allMatch(condition);
}
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda