Can a reflection library that uses Java's module system access non modularized code?

Viewed 118

I'm currently writing a library that uses reflection to access among other things the private fields of a class. Users are expected to use it in a way like Library.function(Class<?> cls);

I'm thinking about putting the packages of that library in a module. However, I'm not sure whether my library would be able to access classes provided by users if they choose to not use Java's module system.

From my understanding, the module system works like this:

  • If I don't modularize my library and the user doesn't use the module system either, no problem here.
  • If I don't modularize my library and the user uses the module system, the packages of my library will be placed in an automatic module which has access to all other modules (other named, and automatic modules, and the unnamed module)
  • If I modularize my library and the user uses the module system, they either have to exports or opens packages.

I'm not sure what happens in the remainig case in which I modularize my library but a user does not. Will they be able to call my library with some class of their own? If yes, what's the reason for it? If not, would I be better off not using the module system?

0 Answers
Related