What exactly is the Hidden Classes feature in Java 15 ?
As i read in Java 15 documentation , Spring & Hibernate frameworks used Hidden Classes ? I need real example to Spring and/or Hibernate used Hidden Classes .
What exactly is the Hidden Classes feature in Java 15 ?
As i read in Java 15 documentation , Spring & Hibernate frameworks used Hidden Classes ? I need real example to Spring and/or Hibernate used Hidden Classes .
To answer this question, it's important to first distinguish the Java language from the Java runtime. The former is the "Java code" a programmer writes, while the latter is the "Java program" people use to run code written in that language (among other languages, like Kotlin and Clojure).
In the Java language, there are many ways to define a class. Most classes are like ArrayList, which are top-level and have a programmer-defined name. But other ways of defining a class may not have a simple name. An anonymous inner class, for example, does not provide a way for a programmer to give it a name. The same goes for lambda expressions introduced in Java 8.
In the past, the Java runtime has had the limitation that all classes must have a name and must be publicly addressable by the runtime. This has meant that the Java compiler gives an anonymous inner class a name unlikely to conflict with any other class's name, usually with dollar signs, which are legal class names to the Java runtime, but illegal class names in the Java language. This is an implementation detail. But because classes all have names and are all addressable through the class loader, abstraction is "leaky"; there are ways these classes which may be meant to be hidden can be addressed through access to the class loader.
"Hidden classes" are a new (to Java 15) feature of the Java runtime, a way for programs to define classes that cannot be addressed by other classes running on the class loader. They still have names, but access is scoped in a way that their existence cannot be "leaked" to other parts of the program. It is not a new language feature, but a tool that a compiler (or runtime framework) may use to implement certain pre-existing language features.
To the typical Java programmer, this process is transparent. Unless your program compiles code or manipulates bytecode, you do not need to worry about this implementation detail. But for those who do, this is a valuable tool in their software toolbox.