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

187
Views
Comparando "largo" y "largo"

Quiero comparar un valor long (tipo primitivo) con otro valor Long (tipo contenedor):

 long x = 5; Long y = 5L; // version 1: only safe, if x is a primitive type var isEqual = x == y; // version 2: y needs to be converted to its primitive type var isEqual = x == y.longValue(); // version 3: using Object.equals(), x will be converted to its wrapper type var isEqual = Objects.equals(x, y);

La pregunta es: ¿Hay algún beneficio en usar la versión 2 en lugar de la versión 3 ?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

La ventaja de Objects.equals(x, y) es que cubre casos nulos. Los dos primeros generarían una NPE si la variable Long es nula.

Por otro lado, Objects.equals(x, y) encuadraría automáticamente el argumento long (primitivo), creando así un objeto. Pero normalmente esto no debería ser una preocupación.

Entonces: solo Objects.equals() porque la comparación involucra un objeto contenedor y para mantener el código simple y legible, de lo contrario, solo verifique la nulabilidad antes de comparar las primitivas con Long.longValue() .

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!