java 代码优化(一)
1.循环优化
缺:
List alist=uSvr.getUserinfoList(); for(int i=0;i<alist.size();i++){}for(int i=0 p=alist.size();i<p;i++){ }for(int i=1;i<=domainCount;i++){ . AuditResult auditResult = new AuditResult(); ..}AuditResult auditResult;for(int i=1;i<=domainCount;i++){ . auditResult=new AuditResult(); ..}try{ Object obj=new Object();}catch(Excepione e){obj=null;}public static Credit getNewCredit() { return new Credit(); } private static Credit BaseCredit = new Credit(); public static Credit getNewCredit() { return (Credit) BaseCredit.clone(); } NewObject object = new NewObject();int value;if(i>0 ){ value =object.getValue();} int value;if(i>0 ){ NewObject object = new NewObject(); Value =object.getValue();} for (val = 0; val < 100000; val +=5) { alterX = val * 8; myResult = val * 2; } for (val = 0; val < 100000; val += 5) { alterX = val << 3; myResult = val << 1; } HttpSession theSession = request.getSession();// 获取当前Sessionif(theSession != null){ theSession.invalidate(); // 使该Session失效}