public static void main(String[] args) { User ut= new User(); setNull(ut); System.out.println(ut.getAge()); // 18 } private static void setNull(User utTemp) { // 本想在這裏將不符合規則的數據全都置爲空, 而後不保存,結果就有問題了 // 這裏只是把引用指向了空, 而沒將對象置爲空,外面的引用仍沒變 utTemp.setAge(18); utTemp = null; System.out.println(utTemp); // null }
其實就是effective 說的 命令式方法(返回新的方法) 或函數式方法(操做傳入的對象並返回)java
2. 代碼很久不更新了 強制pullgit
git fetch --all git reset --hard origin/master git pull
3. jvm
git提交報錯 對象hash值不對函數
error: invalid object 100644 3604ee8e84ee739268b8d170e8cc64b0fe425a65 for 'zipkin-server-2.9.4-exec.jar'
從新計算就能夠了工具
git hash-object -w 文件名
4.在進行兩個Integer比較時, 數不能大於127或小於-128fetch
不然會不從常量池中取數,而是自行建立優化
private static class IntegerCache { static final int low = -128; static final int high; static final Integer cache[]; static { // high value may be configured by property int h = 127; String integerCacheHighPropValue = sun.misc.VM.getSavedProperty("java.lang.Integer.IntegerCache.high"); if (integerCacheHighPropValue != null) { try { int i = parseInt(integerCacheHighPropValue); i = Math.max(i, 127); // Maximum array size is Integer.MAX_VALUE h = Math.min(i, Integer.MAX_VALUE - (-low) -1); } catch( NumberFormatException nfe) { // If the property cannot be parsed into an int, ignore it. } } high = h; cache = new Integer[(high - low) + 1]; int j = low; for(int k = 0; k < cache.length; k++) cache[k] = new Integer(j++); // range [-128, 127] must be interned (JLS7 5.1.7) assert IntegerCache.high >= 127; } private IntegerCache() {} } public static Integer valueOf(int i) { if (i >= IntegerCache.low && i <= IntegerCache.high) return IntegerCache.cache[i + (-IntegerCache.low)]; return new Integer(i); }
5. 使用Arrays 回報 unsupportException 查看以後Arrays 生成的本身的內部arraylist 他和正常的ArrayList 共同繼承了AbstractList 在使用remove時spa
沒有將其實現, 1. 能夠建立個真正的new ArrayList(li) 或使用工具 ColletionUtils.removeAll 即新生成一個新的list,不使用removecode
List<String> li = Arrays.asList(queryVO.getOrdersns()); List<String> li2 = new ArrayList<>(); li.removeAll(li2);
6. 生產上報nullPointException 卻沒有堆棧異常信息,很難肯定是哪一行出的問題?orm
當某個異常拋出次數特別多時,jvm 會優化, 之拋出異常二不打印異常信息, 因此要加上-XX:-OmitStackTraceInFastThrow 禁用該優化
7. 寫存儲過程當中,執行條件
create Produce(CID int)
delete from s1 where cid = CID
本意是cid 是s1的字段, 但因爲傳入的參數包含了CID 因此上面等價於 delete from s1 where true 因此應該替換成delete from s1 where s1.cid = CID