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

273
Views
¿Cómo me especializo en la declaración directa de la interfaz funcional?

Recientemente se me ocurrió la idea de crear el siguiente método:

 /** 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); }

Entonces decidí declarar Function -field en lugar de declarar un método anterior.
La solución no compilable más cercana que podría proporcionar es esta:

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

Esto no está compilado (el IDE resalta la condition dentro allMatch(...) ) por el siguiente motivo:

Mis preguntas:

  1. ¿Es implementable de esa manera o simplemente entiendo mal el concepto de usar interfaces funcionales?
  2. ¿Es posible especializar algún tipo en la declaración Function -s como en el método que he mostrado?
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Para el sistema de tipos, ? de Predicate<?> y ? from Predicate<Iterable<?>> son cosas diferentes. Tu puedes hacer:

 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!