PMD规则之Optimization Rules

·  LocalVariableCouldBeFinal: A local variable assigned only once can be declared final.

翻译   本地变量可以是Final的:本地变量只被赋值一次可以声明为final

·  MethodArgumentCouldBeFinal: A method argument that is never assigned can be declared final.

翻译   方法参数可以是Final的:传入方法的参数从不被赋值可以声明为final

·  AvoidInstantiatingObjectsInLoops: Detects when a new object is created inside a loop

翻译   避免在循环中实例化对象:本规则检查在循环的内部用new创建对象

·  UseArrayListInsteadOfVector: ArrayList is a much better Collection implementation than Vector.

翻译   使用ArrayList代替VectorArrayList是比Vector更好的集合类实现

·  SimplifyStartsWith: Since it passes in a literal of length 1, this call to String.startsWith can be rewritten using String.charAt(0) to save some time.

翻译   简化StartWith:字符串中截取长度为1的字串时,可以用高率一点的String.charAt()代替String.startsWith()

·  UseStringBufferForStringAppends: Finds usages of += for appending strings.

翻译   使用StringBuffer来进行字串append操作:查找使用+=来连接字串的不良方式

·  UseArraysAsList: The java.util.Arrays class has a "asList" method that should be used when you want to create a new List from an array of objects. It is faster than executing a loop to copy all the elements of the array one by one

翻译   使用Arrays类的asList方法:java.util.Arrays类有一个asList方法,当你试图将一个对象数组转换为一个List时应该使用这个方法,这比循环从数据拷贝元素快得多。

·  AvoidArrayLoops: Instead of copying data between two arrays, use System.arraycopy method

翻译   避免数组循环:拷贝数组用System.arraycopy代替循环拷贝数组元素

·  UnnecessaryWrapperObjectCreation: Parsing method should be called directy instead.

翻译   不必要的包装对象创建:解析方法应该被直接调用

·  AddEmptyString: Finds empty string literals which are being added. This is an inefficient way to convert any type to a String.

翻译   加空字符串:发现+“”操作。这是将其他类型转换为字符串的低效的做法

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值