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

179
Views
Problema con el uso opcional (java 8)

Estoy tratando de usar la transmisión con mi código a continuación. Mi problema es mi valor de retorno. Este fragmento de código devuelve un Opcional, no un booleano:

 ogps.stream().filter(elt -> (elt.getLineNumbers() != null && !vg.getLineNumbers().isEmpty())).findFirst();

¿Puedes por favor guiarme? gracias

 //The original code public static boolean isOrderOk(List<OrderGroup> ogps) { if (ogps == null || ogps.isEmpty()) { return true; } for (OrderGroup elt : ogps) { if (elt.getLineNumbers() != null && !vg.getLineNumbers().isEmpty()) { return false; } } return true; } //The new code with stream usage public static boolean isOrderOk(List<OrderGroup> ogps) { if (ogps == null || ogps.isEmpty()) { return true; } return ogps.stream() .filter(elt -> (elt.getLineNumbers() != null && !vg.getLineNumbers().isEmpty())) .findFirst(); return true; }
over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Probablemente estés buscando algo como:

 public static boolean isOrderOk(List<OrderGroup> ogps) { if (ogps == null || ogps.isEmpty()) { return true; } return ! ogps.stream() .anyMatch(elt -> (elt.getLineNumbers() != null && !vg.getLineNumbers().isEmpty())); }
over 4 years ago · Santiago Trujillo Report

0

La razón es que está utilizando el método findFirst de la clase de stream y devuelve el tipo Optional como puede ver aquí .

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!