Reflection and opens
On This Lesson 4 topics
This lesson is planned. The outline below lists the topics it will cover. The full lesson has not been published yet.
In this lesson
explain why frameworks need opens.
Planned topics
exportsallows compile-time and runtime access to public types; it does not allow deep reflection on private members.opensallows reflective access at runtime (includingsetAccessible) to a package.open moduleopens everything;opens ... totargets specific modules.- Frameworks such as Spring, Hibernate, and Jackson reflect on your classes and need them opened.
- Symptom:
InaccessibleObjectExceptionat startup.
Draft outline details
Demonstration
module com.shop.core {
exports com.shop.core.api;
opens com.shop.core.model to com.fasterxml.jackson.databind;
}Check your understanding
Which keyword fixes an InaccessibleObjectException caused by reflection?
Show answer
opens.
Practice
Apply this lesson with the module's lab, exercises and quiz.
Marking a lesson complete is optional and you can undo it any time. Your progress stays in this browser.