标签:thread executor .exe 原因 ted tor err 调用 内部类
Avoid autogenerated methods to access private fields and methods of inner / outer classes
public class Test {
public static void main(final String[] args) {
//code
}
public void test(){
Executors.newSingleThreadExecutor().execute(new Thread() {
@Override
public void run() {
final int a = getNum();
System.out.println(a);
}
});
}
private int getNum() {
return 0;
}
}
在匿名内部类的方法里去调用外部类的私有方法或变量就会报这个PMD错误。
可以将匿名内部类的方法里调用到的外部类的私有方法/变量改成protected。以样例来举例,即将getNum()的权限改为protected:
protected int getNum() {
return 0;
}
PMD - Avoid autogenerated methods to access private fields and methods of inner / outer classes
标签:thread executor .exe 原因 ted tor err 调用 内部类
原文地址:https://www.cnblogs.com/yulinlewis/p/9527278.html