Limitations

We can only create maps with keys that are of type String (or anything super String like CharSequence, Serializable, or Comparable<String>) because, obviously, lambda names are strings.

We must use a Java version that is higher than Java 8u80 because it was at that time that lambda names could be retrieved at runtime.

The most annoying limitation is that we have to compile (i.e. "javac") our code with the "-parameter" flag, or else the parameter names will not be included in the run time package (e.g. JAR or WAR). We can do this automatically by modifying our POM file like this:

If you forget to add the "-parameter" flag, the Java runtime will always report a default name of "arg0" as the name of the parameter. This leads to that the maps will (at most) contain one key "arg0", which is not what we want.

Opportunities

The values, can be of any type. In particular they can be other maps, enabling us to construct more advanced map hierarchies. We could, for example, create a map with different countries with values that are also maps containing the largest towns and how many inhabitants each city has like this:

Update: Important Notes

A number of people have pointed out that SerializedLambda is "thin ice" that we should not rely on in production code. Tagir Valeev (@tagir_valeev) made a performance test of the scheme in this post and compared it to the old fashioned way of just creating a Map and using a regular put() to enter data. The findings were that the old way is orders of magnitudes faster. You can find the entire benchmark here. Thanks Tagir for making this test available.

You should view this way of entering data in a Map as academic an as an inspiration of what can be done in Java. Do not use it in production code.