PMD - Avoid autogenerated methods to access private fields and methods of inner / outer classes
PMD错误
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的更多相关文章
- 【Java基础】Java反射——Private Fields and Methods
Despite the common belief it is actually possible to access private fields and methods of other clas ...
- [Groovy] Private fields and methods are not private in groovy
如题,, 具体介绍请参看: http://refaktor.blogspot.com/2012/07/private-fields-and-methods-are-not.html
- Core Java Volume I — 4.4. Static Fields and Methods
4.4. Static Fields and MethodsIn all sample programs that you have seen, the main method is tagged w ...
- OOP in JS Public/Private Variables and Methods
Summary private variables are declared with the 'var' keyword inside the object, and can only be acc ...
- [置顶] c++,vc6.0,中友元函数,无法访问私有字段(private)的问题(problem),cannot access private member declared in class 'Date'
c++,vc6.0,中友元函数,无法访问私有字段(private)的问题(problem),cannot access private member declared in class 'Date' ...
- CStringArray error C2248: 'CObject::CObject' : cannot access private member declared in class
在开发中将一个字符串分割,并将子字符串保存在CStringArray中,专门写了一个函数,如下: SplitStringToCString(CString str, TCHAR tszSplit, C ...
- error C2248: 'MyString::pCharArray' : cannot access private member declared in class 'MyString'
std::ostream & operator<<(std::ostream os,const MyString & mystr){os<<mystr.pCha ...
- docker postgresql FATAL: could not access private key file "/etc/ssl/private/ssl-cert-snakeoil.key": Permission denied
在docker中启动postgresql时出现错误 FATAL: could not access private key file "/etc/ssl/private/ssl-cert- ...
- deque Comparison of Queue and Deque methods Comparison of Stack and Deque methods
1. 队列queue和双端队列deque的转换 Queue Method Equivalent Deque Methodadd(e) addLast(e)offer(e) offerLast(e)re ...
随机推荐
- struts2_13_OGNL表达式
全称:Object Graphic Navigation Language(对象图导航语言)是一个开源项目,是Struts2框架的默认表达式语言. 相对于EL表达式.它提供了平时我们须要的一些功能,如 ...
- hud 1465、2049、2045 (递推)[含简单C(n,m) n!的写法]
C - 不容易系列之一 Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit ...
- 常用DOS下MSC指令
xp:copy C:\WINDOWS\repair\*.* 到 c:\windows\system32\config 2k: copy C:\winnt\repair\*.* 到 c:\winnt\s ...
- gcc在出现错误的时候停止编译 -Wfatal-errors
有时候我们编译一个大的项目的时候.会出现非常多错误使得屏幕堆满了非常多没用的信息.普通情况下我们须要找到首次出现错误的地方,在gcc中加入编译选项能够使编译停止在第一次出现错误的地方: $ gcc - ...
- 利用BADI WORKORDER_INFOSYSTEM在COOIS中加入自己定义列办事处
需求描写叙述:依据LC业务部门提出的需求.须要在COOIS中加入办事处一列. 1.在IOHEADER_TAB的CI_IOHEADER中加入字段办事处.如以下图所看到的: watermark/2/t ...
- pageHelper没有分页效果的问题
配置完全都没有问题 springboot pagehelper分页怎么都不管用 而且所有的信息记录全部都查出来了 解决方法: PageHelper.startPage(pageNum,pageSize ...
- javascript flash 弹框
1. [代码]FlashBox // JavaScript Documentfunction FlashBox(src,width,height){var docbody = document ...
- [Selenium] 使用自定义的FirefoxProfile
FirefoxProfile 用于定制待测试的Firefox 浏览器的特定属性,其中包括所存储的密码.书签.历史信息.Cookies等.某些测试用例需要用到特定的用户信息,因此可通过定制当前Firef ...
- 洛谷P1290 欧几里德的游戏
题目:https://www.luogu.org/problemnew/show/P1290 只要出现n>=2*m,就可以每次把较大的数控制在较小的数的一倍与二倍之间,则控制了对方的走法: 每次 ...
- bzoj1089严格n元树——DP+高精度
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1089 f[d]为深度小于等于d的树的个数: 从根节点出发,有n个子树,乘法原理可以得到 f[ ...