屏蔽sonar2种方式:
1、在类上加入@SuppressWarnings("all")
2、在代码后方加入 // NOSONAR
错误:make the enclosing method static or remove this set
不要使用非静态方法去更新静态字段,这样很难获得正确的结果,
如果有多个类实例和/或多个线程,则很容易导致错误。理想情况下,静态字段仅从同步静态方法中更新。
static name = "11";
public void getName(){
name = "11"
}
错误:Define a constant instead of duplicating this literal “11” 3 times.
定义一个常量,而不是将这个文字“11”复制3次。
把重复得抽出来,不要过多出现重复代码。
错误:Complete cases by adding the missing enum constants or add a default case to this switch.
switch缺少默认返回default,要加default。
switch (param) {
case 0:
doSomething();
break;
case 1:
doSomethingElse();
break;
default:
error();
break;
}