看这里的例子
从2.4开始,已将方法添加到Logger接口以支持lambda表达式。新方法允许客户端代码懒惰地记录消息,而无需显式检查是否启用了请求的日志级别。例如,以前一个会写:
// pre-Java 8 style optimization: explicitly check the log level// to make sure the expensiveOperation() method is only called if necessary if (logger.isTraceEnabled()) { logger.trace("Some long-running operation returned {}", expensiveOperation()); }
使用Java 8,可以通过lambda表达式实现相同的效果:
// Java-8 style optimization: no need to explicitly check the log level:// the lambda expression is not evaluated if the TRACE level is not enabledlogger.trace("Some long-running operation returned {}", () -> expensiveOperation());
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)