Comments on: Creating Maps With Named Lambdas https://speedment.com/creating-maps-with-named-lambdas/ Build Fast Java Applications for the Fastest Business Performance Fri, 01 May 2020 05:21:37 +0000 hourly 1 https://wordpress.org/?v=5.1.1 By: Per Minborg https://speedment.com/creating-maps-with-named-lambdas/#comment-99 Fri, 09 Dec 2016 16:49:17 +0000 https://speedment.com/creating-maps-with-named-lambdas/#comment-99 Interesting observations. As you point out, this is only for code that is not performance sensitive. In fact, the code is more to show that it can be done rather than something else. More of an academic fact. I would not recommend people to use this in production code. It would be fun to do this for Java 9 too and see how it can be done there too. Perhaps in a future post.

]]>
By: Nicolai Parlog https://speedment.com/creating-maps-with-named-lambdas/#comment-100 Fri, 09 Dec 2016 11:24:04 +0000 https://speedment.com/creating-maps-with-named-lambdas/#comment-100 I really like the idea to play around with lambdas this way. But there are more limitations than the ones you mention:

As Tagir Valev pointed out on Twitter, this is significantly slower than doing it the usual way. I would not consider that overly important as it is unlikely that this is called in performance sensitive code. I'd guess `mapOf` is most likely used to initialize constants.

But he also points out that this conflicts with strong encapsulation in Java 9. I just tried it out and indeed, the serialized lambda belongs to the module that calls `mapOf`, which means that the module containing `KeyValueStringFunction` tries to break into the former with reflection, which doesn't work out of the box.

]]>