Java知识分享网 - 轻松学习从此开始!    

Java知识分享网

Java1234官方群25:java1234官方群17
Java1234官方群25:838462530
        
SpringBoot+SpringSecurity+Vue+ElementPlus权限系统实战课程 震撼发布        

最新Java全栈就业实战课程(免费)

springcloud分布式电商秒杀实战课程

IDEA永久激活

66套java实战课程无套路领取

锋哥开始收Java学员啦!

Python学习路线图

锋哥开始收Java学员啦!
当前位置: 主页 > Java文档 > Java基础相关 >

JAVA PMD规则 详解 PDF 下载


分享到:
时间:2023-09-11 10:33来源:http://www.java1234.com 作者:转载  侵权举报
JAVA PMD规则 详解
失效链接处理
JAVA PMD规则 详解 PDF 下载

 
 
 
相关截图:
 
主要内容:


The Basic Ruleset contains a collection of good practices which everyone should follow. · EmptyCatchBlock: Empty Catch Block finds instances where an exception is caught, but nothing is done. In most circumstances, this swallows an exception which should either be acted on or reported. 翻译 空的 catch 块:发现空的 catch 块没做任何异常处理的事,在大多数情形下,这会 吞噬一些应该被处理或报告的异常 · EmptyIfStmt: Empty If Statement finds instances where a condition is checked but nothing is done about it. 翻译 空的 if 表达式:发现使用 if 进行了条件判断,但是判断之后没做任何处理 · EmptyWhileStmt: Empty While Statement finds all instances where a while statement does nothing. If it is a timing loop, then you should use Thread.sleep() for it; if it's a while loop that does a lot in the exit expression, rewrite it to make it clearer. 翻译 空的 while 表达式:发现空的 while 表达式,如果是一个定时的循环,你应该在循 环体内使用 Thread.sleep() ;如果是对于退出处理做的一个处理大量事情的 while 循环,重 写代码使它更清晰 · EmptyTryBlock: Avoid empty try blocks - what's the point? 翻译 空的 try 块:避免空的 try 块 · EmptyFinallyBlock: Avoid empty finally blocks - these can be deleted. 翻译 空的 finally 块:避免空的 finally 块 - 这些是可以删掉的 · EmptySwitchStatements: Avoid empty switch statements. 翻译 空的 switch 表达式:避免空的 switch 表达式 · JumbledIncrementer: Avoid jumbled loop incrementers - it's usually a mistake, and it's confusing even if it's what's intended. 翻译 避免混乱的循环 增量 - 它常常是一个错误,而且容易让人迷惑 错误代码示例: public class JumbledIncrementerRule1 { public void foo() { for (int i = 0; i < 10; i++) { for (int k = 0; k < 20; i++) { System.out.println("Hello"); } } } } 父子循环都用 i++ · ForLoopShouldBeWhileLoop: Some for loops can be simplified to while loops - this makes them more concise. 翻译 有些 for 循环可以简化为 while 循环 - 这样可以更加简明 代码示例: public class Foo { void bar() { for (;true;) true; // 没有初始化块和变化块,相当于 : while (true) } } · UnnecessaryConversionTemporary: Avoid unnecessary temporaries when converting primitives to Strings 翻译 将原始类型转换为字符串类型时不必要的临时转换 代码示例: public String convert(int x) { // 多了一个创建对象环节 String foo = new Integer(x).toString(); // 下面这种写法就好了 return Integer.toString(x); }




 
------分隔线----------------------------

锋哥公众号


锋哥微信


关注公众号
【Java资料站】
回复 666
获取 
66套java
从菜鸡到大神
项目实战课程

锋哥推荐