Baz*_*Baz 8 java static code-analysis findbugs
我在我的应用程序中有几个区域,我从实例方法操作静态变量的值时得到错误.
"从实例方法写入静态字段".
如果我们将多线程排除在等式之外,即使多个实例写入同一个static变量,这种情况是否会造成任何潜在的问题?
Not*_*bug 20
从文档......
此实例方法写入静态字段.如果操作多个实例并且通常是不好的做法,这很难得到纠正.
第二件事是关于提出任何潜在问题的问题
如果您正在static从实例方法操作一个字段,那么类的任何对象(包含我们的实例方法的类)可能正在调用该方法,并且很难找到static已经开发的一些大型应用程序或应用程序中的对象操作字段.由他人编码.
这个答案也可以帮到你.
编辑:
仅供参考,您可以在以下代码中绕过findbug的警告.
class TestClass {
static int testInt = 0 ;
public static setTestInt ( int a ) {
TestClass.testInt = a ;
}
public void setInt ( int a1 ) {
setTestInt ( a1 );
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
18019 次 |
| 最近记录: |