1

When I declare a private variable in my class that is not used, I expect to get a warning.

private JavaScriptSupport jsSupport;
// Warning: The value of the field MyClass.jsSupport is not used

When I add Apache Tapestry's @Inject-Annotation The warning disappears - but why?

@Inject
private JavaScriptSupport jsSupport;
// No warning

To my understanding, there is no use of unused private variables, even if the get a value injected. Is there a way to define a warning in CheckStyle for this case?

Edward
  • 4,453
  • 8
  • 44
  • 82
  • http://stackoverflow.com/questions/11447910/eclipse-juno-why-no-warning-on-unused-annotated-private-field – Sotirios Delimanolis Feb 11 '15 at 15:50
  • In your case it's a reference type: the injected instance can perform side-effects in its constructor which makes one reason why this should be expected behaviour. – Jeroen Vannevel Feb 11 '15 at 15:51
  • 2
    However, it is possible to to check for unused variables in checkstyle? – Edward Feb 11 '15 at 16:10
  • I think you'll find the answer here: [How to check “The value of the local variable/field is not used” in Checkstyle?](http://stackoverflow.com/a/20133122/1005481) – barfuin Feb 16 '15 at 21:25

0 Answers0