Skip to content
Ameen Abozaid
Planned lessonMID-010-L03

Reflection and opens

  • Lesson 3 of 5
  • Mid-level
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

  • exports allows compile-time and runtime access to public types; it does not allow deep reflection on private members.
  • opens allows reflective access at runtime (including setAccessible) to a package.
  • open module opens everything; opens ... to targets specific modules.
  • Frameworks such as Spring, Hibernate, and Jackson reflect on your classes and need them opened.
  • Symptom: InaccessibleObjectException at startup.
Draft outline details

Demonstration

java
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.

Lab and exercises Quiz

Marking a lesson complete is optional and you can undo it any time. Your progress stays in this browser.

Continue to next lesson

Type to search levels, phases, modules and lessons.