Class HiddenClassesExamples
java.lang.Object
net.jrodolfo.java_evolution.java15.hidden_classes.HiddenClassesExamples
Demonstrates hidden classes, introduced in Java 15 by JEP 371.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classCompiled template used as class-file bytes for the hidden class definition. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleancanFindByName(Class<?> hiddenClass) Checks whether normal class-name lookup can discover a hidden class.Class<?> Defines a hidden class from the compiled bytes of the nested template class.invokeHiddenClassMethod(Class<?> hiddenClass) Invokes behavior on an instance of the hidden class.booleanReports whether a class is hidden.
-
Constructor Details
-
HiddenClassesExamples
public HiddenClassesExamples()
-
-
Method Details
-
defineHiddenTemplateClass
Defines a hidden class from the compiled bytes of the nested template class.- Returns:
- hidden class metadata
- Throws:
IOException- when the template class bytes cannot be readIllegalAccessException- when the lookup cannot define the hidden class
-
isHidden
Reports whether a class is hidden.- Parameters:
type- class to inspect- Returns:
- whether the class is hidden
-
invokeHiddenClassMethod
public String invokeHiddenClassMethod(Class<?> hiddenClass) throws NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException Invokes behavior on an instance of the hidden class.- Parameters:
hiddenClass- hidden class to instantiate- Returns:
- message returned by the hidden instance
- Throws:
NoSuchMethodException- when the expected constructor or method is missingInvocationTargetException- when the constructor or method throws an exceptionInstantiationException- when the hidden class cannot be instantiatedIllegalAccessException- when access checks reject construction or invocation
-
canFindByName
Checks whether normal class-name lookup can discover a hidden class.- Parameters:
hiddenClass- hidden class to look up by name- Returns:
- whether
Class.forName(String)finds the hidden class
-