java編碼規範常見錯誤

1.Merge this if statement with the enclosing onejava

應該合併可摺疊的語句this

2.String a = null;日誌

須要初始化 String a;排序

3.捕捉到的異常 用日誌打印ci

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

4.判斷是否大於0(是否爲空)string

不用orderMainBeanList.size() > 0it

使用 !orderMainBeanList.isEmpty()io

5.case  1ast

    ...

這裏的業務不能大於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(){}  

相關文章
相關標籤/搜索