Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I give lambda a name?

I have nice functional code roughly of next shape (ComponentRegistry.java):

public void doExport() {
    config.exports().forEach((key, type) -> {
        ...
    }
}

The problem with it that when it comes to log4j statements it produces next output:

ComponentRegistry lambda$doExport$1

Where actual method name comes after "lambda" keyword and then there are two hints about anonymous classes ($). It simply not as good as direct method call logging.

I was wondering whether anyone came with way to properly label lambdas in log4j output or stacktraces because it would be awesome.

like image 623
Petro Semeniuk Avatar asked Oct 18 '25 14:10

Petro Semeniuk


1 Answers

If you want to give it a name, don't use a lambda (which is explicitly an anonymous function). Instead break it out into its own class.

like image 200
jacobm Avatar answered Oct 20 '25 04:10

jacobm



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!