2

I was reading JLS-14 and in a chapter about modules I saw a statement like this

Distinct from access at compile time and access at run time, the Java SE Platform provides reflective access via the Core Reflection API (§1.4). A normal module grants reflective access to types in only those packages which are explicitly exported or explicitly opened (or both). An open module grants reflective access to types in all its packages, as if all packages had been opened.

So I wonder what does runtime access mean here, as til now I was thinking that in terms of modules, the meaning of runtime access was the same as reflective access

Naman
  • 27,789
  • 26
  • 218
  • 353
JovoH
  • 138
  • 6
  • Stuff like `Foo.bar()`. If you try to access an internal package, you will get an error (not sure which one exactly right now). – Johannes Kuhn Jul 13 '20 at 02:40
  • 1
    I think it just means typical method invocations and such. For instance, you could compile your code with `--add-exports` / `--add-opens` to gain access to internal code of another module but then fail to add those same options at run time, thus getting an access error only at run time. – Slaw Jul 13 '20 at 03:49
  • I agree with you that using these options at runtime will cause an error, but I don't think that this is the answer of the question.The options that you mentioned are just a way that java provides as to treat the module as it has a *module-info.java* file, with *exports* and *opens*. – JovoH Jul 13 '20 at 05:29
  • 1
    The point is you have to specify the options _both_ at compile time _and_ at run time (if you want access to internal code you otherwise would not). I mentioned the options as an example of how there's "access at compile time" and "access at run time", each distinct from the other and neither of which use reflection. – Slaw Jul 13 '20 at 06:10
  • 1
    Runtime is the natural counter-part to compile-time. It has nothing to do with Reflection. – Holger Jul 13 '20 at 16:17
  • @Holger this is exactly what I want to know by saying what is that **natural counter-part of compile time?** – JovoH Jul 13 '20 at 17:08
  • 2
    I don't know how to say it, as it is so fundamental. When you do `javac ...`, that's compile-time. Only afterwards, at some time, you can do `java ...` to execute the compiled code. That's runtime. You can write a program that does not use Reflection at all. Still, there is a time when you run it, which is runtime. – Holger Jul 13 '20 at 19:44
  • I know what is runtime and what is compile time. Please reread my question. I'm asking what does Runtime **access** mean? – JovoH Jul 14 '20 at 02:52
  • 3
    It means the same thing as compile time access, just at run time. – Slaw Jul 14 '20 at 05:29
  • 1
    My previous comment was a response to [this comment](https://stackoverflow.com/questions/62868467/modules-runtime-access#comment111196600_62868467). When these terms are understood, using them to attribute the term “access” should be no problem anymore. You can use [Slaw’s approach](https://stackoverflow.com/questions/62868467/modules-runtime-access#comment111210349_62868467) or you consider “runtime access” to be the same as “reflective access”, but *not* using Reflection but ordinary language constructs. – Holger Jul 14 '20 at 16:35

0 Answers0