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

145
Vistas
Can be replaced with method reference using reflection in java

I have this code in intellij:

 return collection.stream().anyMatch(annotation -> 
                        method.isAnnotationPresent(annotation));

And the compiler tells me that "method.isAnnotationPresent(annotation)" can be replaced with method reference and I can't figure out how to do it because it has an argument.

Does anyone know how to make that?

about 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

You can replace your code to use the method reference (look here) as shown below:

return collection.stream().anyMatch(method::isAnnotationPresent);

Basically, you are providing the isAnnotationPresent() method definition to the Lambda expression (of anyMatch method which accepts for Predicate) and the value from the stream will automatically be passed as an argument to the anyMatch method.

about 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