In JShell, if I do this:
interface Foo { String foo(); }
(Foo) () -> "hi"
I get
| created interface Foo
$2 ==> $Lambda$15/0x00000008000a9440@32e6e9c3
From the research below, I know the following:
$15 = an object reference to the AIC
@32e6e9c3 = the sequential number of the object created--at least, in IntelliJ
But what does the / (slash) indicate, as in /0x00000008000a9440?
Summary
$Lambda$15/0x00000008000a9440is the name of the created hidden class.As it will be shown below,
0x00000008000a9440is called a suffix.The name of the class can be retrieved by calling the
java.lang.Class.getName()method. Therefore:Example program to show name of hidden class
ProgramclassProgram output
Documentation references
JEP 371: Hidden Classes
The hidden classes have been introduced since JDK 15. For additional details, please, refer to the JEP: JEP 371: Hidden Classes.
Here is an excerpt from the JEP on the hidden class names:
Javadoc:
java.lang.Class#getName()methodLet's refer to the method documentation: Class (Java SE 15 & JDK 15).
An excerpt from the documentation:
Implementation details: OpenJDK Java Virtual Machine: Hidden class name
Introduction
Let's consider the source code of OpenJDK 18.
Let's refer to the tag: openjdk/jdk18 at jdk-18+37.
Please, note that:
18.0.1-ea+10-Debian-1.Hidden class name mangling
Hidden class creation (the
java.lang.invoke.MethodHandles.Lookup.defineHiddenClass()method) includes the mangling of its name.Let's consider the following call stack:
Then let's consider the following execution path as the continuation of the call stack:
Let's refer to the piece of source code: jdk18/classFileParser.cpp at jdk-18+37 · openjdk/jdk18:
Please, note that the
+character is used as the separator.Get hidden class name
The
java.lang.Class#getName()method includes the character replacement:+is replaced with/.Let's consider the following execution path:
Let's refer to the piece of source code: jdk18/klass.cpp at jdk-18+37 · openjdk/jdk18: