Eclipse duplication annotation @SurpressWarnings f

2019-08-02 11:34发布

I am trying to disable several arbitrary PMD warnings for my class.

How can I list several PMD rules to be ignored? I was not able to find with Google.

@SuppressWarnings("PMD.OnlyOneReturn")
@SuppressWarnings("PMD.ShortVariable")
public class MyClass {

it gives Eclipse compile time error:

Duplicate annotation @SurpressWarnings

This is compilable but ignored

@SuppressWarnings("PMD.OnlyOneReturn, PMD.ShortVariable")

This

@SuppressWarnings("PMD.OnlyOneReturn", "PMD.ShortVariable")

result is

Syntax error on token ,

Eclipse is configured to accept PMD type:

Unsupported @SuppressWarnings ( "PMD.DoNotCallSystemExit" )

2条回答
该账号已被封号
2楼-- · 2019-08-02 12:01

You have to list them in an array.

Like this:

@SuppressWarnings({
    "PMD.OnlyOneReturn",
    "PMD.ShortVariable"  })
查看更多
3楼-- · 2019-08-02 12:10

Found just now in Annotation Type SuppressWarnings.

This seems to work, note { and }, since it is String[]:

@SuppressWarnings({"PMD.OnlyOneReturn", "PMD.ShortVariable"})
查看更多
登录 后发表回答