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

144
Views
Usando Class<T> con inmutables

Estoy probando la biblioteca immutables.org. Lo que necesito es poder especificar una clase, así que he definido

 @Value.Immutable public interface Value<T> { Class<T> getType(); }

El constructor generado por inmutables no acepta esto.

 ImmutableValue.builder().type(String.class)...

Porque espera un Class<Object>. ¿Cómo hago para que el constructor acepte String.class?

Anotar el tipo con @Value.Parameter crea muy bien un método que funciona

 ImmutableValue.of(String.class)...

Pero el resultado es una instancia, no un constructor, por lo que los valores de seguimiento solo se pueden establecer con la cruz.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Puede inferir el tipo usando el tipo testigo .

 public class ImmutableExample { public static void main(String[] args) { ImmutableValue immutableValue = ImmutableValue.<String>builder() .type(String.class).build(); System.out.println(immutableValue.getType()); } }
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!