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

224
Vistas
Why doesn't javac produce a warning when using a deprecated constructor of a parameterized type?

Say you have a parameterized class with a deprecated constructor, and a User class that calls this constructor. In the example below, using the diamond operator, javac (version 11.0.11) does not produce a deprecation warning:

class DepTester<T> {
    T t;

    @Deprecated
    public DepTester(T t) {
        this.t = t;
    }
}

class User {
    DepTester<String> tester = new DepTester<>("This does not produce a warning!");
}

However, with an explicit type argument in the constructor call, the warning is issued:

class User {
    DepTester<String> tester = new DepTester<String>("This produces a warning.");
}

[WARNING] DepTester.java:[17,40] DepTester(T) in com.foo.DepTester has been deprecated

The explicit type argument is normally not included, which IntelliJ inspection also warns about:

Explicit type argument String can be replaced with <>

I can't find an explanation for this behaviour in the Java language spec. I tried with javac 17, and it produces a warning in both cases, so is this a bug in javac 11?

EDIT: My bug report to Oracle was assigned an ID in the Java bug database: JDK-8281107

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

0

You encountered bug JDK-8257037, “No javac warning when calling deprecated constructor with diamond”:

No deprecation warning is emitted when compiling a class that calls a deprecated constructor when using the diamond syntax to specify the generic types. A deprecation warning is emitted when calling the same constructor using an explicit type argument or a raw type.

It has been fixed with JDK 17.
There’s also a reported backport to JDK 16, but none for earlier versions.

over 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