Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

269
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!