java编码规范常见错误

1.Merge this if statement with the enclosing one

应该合并可折叠的语句

2.String a = null;

需要初始化 String a;

3.捕捉到的异常 用日志打印

} catch (Exception e) {
      Log logger.info(e);
     //或者 Logger logger.info("",e);
}

4.判断是否大于0(是否为空)

不用orderMainBeanList.size() > 0

使用 !orderMainBeanList.isEmpty()

5.case  1

    ...

这里的业务不能大于5行,如果大于5行,另写一个private的方法去写这里的业务,然后这里调用。


6.public static final String GET_VIEW_ROWS

不是public final static  String GET_VIEW_ROWS

7.Replace the type specification in this constructor call with the diamond operator ("<>"). (sonar.java.source not set. Assuming 7 or greater.)  

Map<String, String> M_FILETYPES= new HashMap<String, String>();

改成

Map<String, String> M_FILETYPES= new HashMap<>();

8.方法名称排序

先构造

再有参构造

再其他方法

9.return null改成  Collections.emptyList();

10.NullPointerException might be thrown as 'dt2' is nullable here

先判断是否为空再去操作

11.Introduce a new variable instead of reusing the parameter "prefixKey"

不要用传递过来的参数去重新赋值做判断等

可以新建一个参数  等于传递过来的参数  用新的参数去操作

private String getBatchSaveKey(Map<String, String> map, String prefixKey, String... keys) {
        //创建一个newPrefixKey
        String newPrefixKey;
        newPrefixKey = prefixKey.endsWith(RedisKeys.DELIMITER) ? prefixKey.substring(0, prefixKey.length() - 1) : prefixKey;
        if (keys.length == 0) {
            return newPrefixKey;
        }

不直接用prefixKey = prefixKey.endsWith(RedisKeys.DELIMITER) ? prefi。。。
也不直接用return prefixKey;而是去创建newPrefixKey

12.Cast one of the operands of this division operation to a "double"

使用int pageSize=(int) Math.ceil(count/3);

需要转double  int pageSize=(int) Math.ceil((double) count/3);

13.Add a nested comment explaining why this method is empty, throw an UnsupportedOperationException or complete the implementation

对于bean里面的类 手写构造
  public  CodeBean(){}
 

转载于:https://my.oschina.net/u/3559695/blog/1795231

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值