RFR: JDK-8005263: Logging APIs takes Supplier<String> for message

Brian Goetz brian.goetz at oracle.com
Sun Dec 23 10:45:08 PST 2012


>> Henry - just a quick comment on the class description. I think it would
>> be better not to include the sentence "Since 1.8 ..." as it that will
>> quickly become a historical note. It would be much better (in my view)
>> to just highlight the methods with something like "Several of the
>> methods take a Supplier function ..." and make the potential performance
>> benefit of using these methods clear.
>
> You should also add a note saying that the supplier can be specified as
> a lambda and in that case, the lambda *must* not capture value of local
> variable, otherwise a supplier object will be created each time you log
> something.

No, don't do this.

First of all, just because the performance characteristics of capturing 
lambdas are one way today on HotSpot compared to non-capturing, does not 
mean we should burn this into spec.  Also, there's no way to enforce it.

More importantly, a capturing lambda might still be way better than a 
String, as in this example:

   log(DEBUG, () -> "Children of " + name + ": " + getChildrenOf(name));

Collecting getChildren (and turning it into a String) commonly involves 
something thousands of times as expensive as an object creation.


More information about the lambda-dev mailing list