I want to make my logging more efficient by using lazy logging in Log4J2.
This means I'm using lambdas, which are only executed when the log level is correct/fulfilled.
Example:
List<Integer> someList = Arrays.asList(1,2,3);
log.info("Size of list is {}.", () -> someList.size());
My IDE tells me, that I can replace this notation with the method reference like so:
log.info("Size of list is {}.", someList::size);
My question is now: Does this approach (method reference) still have the benefit of lazy logging, i.e. that an expensive computational task is only executed in the logging, when the log level is fulfilled or do I lose the whole benefit, when I'm not using lambdas explicitly?