推荐使用java.util.Objects.equals(Object, Object)。
反例:HashMap放置1024个元素,随着元素不断增加,需要resize7次,严重影响性能。
JDK8用DateTimeFormatter(This class is immutable and thread-safe)代替SimpleDateFormat。
if (log.isInfoEnabled()) {
log.info("Processing trade with id:" + id + " and symbol:" + symbol);
}
log.info("Processing trade with id:{} and symbol:{}", id, symbol);
当日志级别为error时,这两种都不会执行字符串拼接操作和toString()方法,节省系统资源。在强调一点高并发系统线上千万不能有System.out.println()。
简化代码空判断,防止NPE。
List<PromoIndex> promoIndexList = getBatchPromoStoresIndexs(promo, sku);
if (CollectionUtils.isNotEmpty(promoIndexList)) {
for (PromoIndex index : promoIndexList) {
}
}
与int常量相比,枚举要易读的多,也更加安全,功能更加强大。
后面持续更新!!!
原文:https://www.cnblogs.com/wudiffs/p/11361993.html