Java

Java

Made by DeepSource

@Inject detected on a final field JAVA-W1071

Anti-pattern
Major
Autofix

@javax.inject.Inject should not be used on final fields.

JSR-330 forbids the use of @Inject on final fields. Many popular libraries such as Guice have adopted the convention and disallowed @Inject on final fields. It's highly encouraged to write code that follows this convention.

Bad Practice

import @javax.inject.Inject;

public class Klass {
    @Inject
    private final String name;
}

Recommended

Just remove @Inject from final fields.

public class Klass {
    private final String name;
}

References

  • Oracle Java EE 6 Javadocs - @Inject