Mongoosej.Blog.Software.Programming.Java.Aspect.经典代码
List中remove()方法的陷阱,被坑惨了!
原来 Lamda 表达式是这样写的
获取调用栈
// springboot利用栈跟踪获取启动类
private Class<?> deduceMainApplicationClass() {
try {
StackTraceElement[] stackTrace = new RuntimeException().getStackTrace();
for (StackTraceElement stackTraceElement : stackTrace) {
if ("main".equals(stackTraceElement.getMethodName())) {
return Class.forName(stackTraceElement.getClassName());
}
}
}
catch (ClassNotFoundException ex) {
// Swallow and continue
}
return null;
}
枚举valueOf方法捕获异常
try {
// valueOf是枚举类的默认方法,该方法如果根据key找不到没觉会抛出IllegalArgumentException
DB100.valueOf(key);
} catch(IllegalArgumentException e) {
continue;
}