score:67

Accepted answer

In the code in your question, the @SuppressWarnings("unused") annotation is unnecessary because the method is either overriding another method from a superclass or implementing an interface. Even if you don't actually use the whatever parameter it's mandatory to declare it, otherwise the @Override annotation will produce an error (you'd be changing the signature of the overridden method if you removed the parameter.)

In some older versions of Eclipse the code as shown would not cause a warning, but in more recent releases it does. I believe it's a valid warning, and I'd rather remove the @SuppressWarnings("unused") in this case.

score:5

Alternatively, if you think it's more correct to delete the SuppressWarnings annotation:

Window -> Preferences -> Java -> Compiler -> Errors/Warnings -> Unnecessary code -> Value of parameter is not used

and select Ignore in overriding and implementing methods

score:5

In my code there's no inheritance defining the 3 methods with @SuppressWarnings("unused")

This code gives 'Unnecessary @SuppressWarnings("unused")' in Eclipse Juno (latest version), but if I remove the @SuppressWarnings("unused"), I get "Constructor/Method is never used" warnings in IntelliJ IDEA 11.1.3

The methods aren't directly used in the project, only by 3rd party products Jackson, JAXB & GSON, so IntelliJ is right, I would say ...

public class EmailUnsendable extends SkjemaError {

    private NestedCommand command;        // Can't be Command (interface) because of GSON!

    @SuppressWarnings("unused")            // Used by Jackson/JAXB/GSON
    public EmailUnsendable() {
    }

    public EmailUnsendable(String referenceNumber, String stackTrace, NestedCommand command) {
        super(referenceNumber, stackTrace);
        this.command = command;
    }

    @SuppressWarnings("unused")            // Used by Jackson/JAXB/GSON
    public NestedCommand getCommand() {
        return command;
    }

    @SuppressWarnings("unused")            // Used by Jackson/JAXB/GSON
    public void setCommand(NestedCommand command) {
        this.command = command;
    }
}

I believe this is an error in Eclipse.

score:25

Go to

WindowPreferencesJavaCompilerErrors/WarningsAnnotations.

And select Ignore for Unused '@SuppressWarnings` token.


Related Query

More Query from same tag