Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

232
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda