Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

270
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda