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的更多相关文章

  1. 【Java基础】Java反射——Private Fields and Methods

    Despite the common belief it is actually possible to access private fields and methods of other clas ...

  2. [Groovy] Private fields and methods are not private in groovy

    如题,, 具体介绍请参看: http://refaktor.blogspot.com/2012/07/private-fields-and-methods-are-not.html

  3. 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 ...

  4. 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 ...

  5. [置顶] 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' ...

  6. CStringArray error C2248: 'CObject::CObject' : cannot access private member declared in class

    在开发中将一个字符串分割,并将子字符串保存在CStringArray中,专门写了一个函数,如下: SplitStringToCString(CString str, TCHAR tszSplit, C ...

  7. error C2248: 'MyString::pCharArray' : cannot access private member declared in class 'MyString'

    std::ostream & operator<<(std::ostream os,const MyString & mystr){os<<mystr.pCha ...

  8. 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- ...

  9. 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 ...

随机推荐

  1. 开源项目:单行日历(CalendarView)

    http://www.cnblogs.com/warnier-zhang/p/4750525.html CalendarView.zip

  2. excel 创建数据有效性及背景颜色

    需求:用excel做数据或者表格时经常需要在一列中给出固定的几个进行悬着,这是如果每次键盘输入降低工作效率.如果做成鼠标双击进行选择,则提高很多效率,比如需要给一列填写Pass或Failure时,具体 ...

  3. scala进阶笔记:函数组合器(combinator)

    collection基础参见之前的博文scala快速学习(二). 本文主要是组合器(combinator),因为在实际中发现很有用.主要参考:http://www.importnew.com/3673 ...

  4. 在C++中使用Libmd5计算字符串或文件的MD5值

    CppMD5Demo.cpp #include <iostream> #include <fstream> #include <chrono> #include & ...

  5. 命令行唤起xcode模拟器

    1.IOS模拟器列表获取命令 xcrun instruments -s 2.IOS启动模拟器命令 xcrun instruments -w "iPhone 8 (12.1)"

  6. Vue 中的受控与非受控组件

    Vue 中的受控与非受控组件 熟悉 React 的开发者应该对"受控组件"的概念并不陌生,实际上对于任何组件化开发框架而言,都可以实现所谓的受控与非受控,Vue 当然也不例外.并且 ...

  7. vue中引入字体文件

    在用vue来写一官网的时候,想引入外部字体文件,毕竟总感觉他自己的字体有点难看,在这里记录下 1.先下载字体文件所需的.ttf文件 我这里想引入的是华文行楷字体 百度后下载了一个3M多的ttf文件 2 ...

  8. YTU 2578: 分数减法——结构体

    2578: 分数减法--结构体 时间限制: 1 Sec  内存限制: 128 MB 提交: 522  解决: 399 题目描述 分数可以看成是由字符'/'分割两个整数构成,可以用结构体类型表示.请用结 ...

  9. lovelygallery_popup(卡哇依相册)

    /*************************** 相册 ***************************/LovelyGallery 功能特点:超过200个令人惊叹的3D&2D硬 ...

  10. jsp的4大作用域

    jsp的4大作用域 首先要声明一点,所谓“作用域”就是“信息共享的范围”,也就是说一个信息能够在多大的范围内有效.4个JSP内置对象的作用域分别为:application.session.reques ...