Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>There is is nothing wrong with JLS or javac. Of course this doesn't compile, because your class <code>MessageHolder</code> references <code>MessagePrinterInternal</code> which is not on the compile classpath if I understand your explanation right. You have to break this reference into the implementation, for example with an interface in your API.</p> <p>EDIT 1: For clarification: This has nothing to do with the package-visible method as you seem to think. The problem is that the type <code>MessagePrinterInternal</code> is needed for compilation, but you don't have it on the classpath. You cannot expect javac to compile source code when it doesn't have access to referenced classes.</p> <p>EDIT 2: I reread the code again and this is what seems to be happening: When MyApp is compiled, it tries to load class MessageHolder. Class MessageHolder references MessagePrinterInternal, so it tries to load that also and fails. I am not sure that is specified in the JLS, it might also depend on the JVM. In my experience with the Sun JVM, you need to have at least all statically referenced classes available when a class is loaded; that includes the types of fields, anything in the method signatures, extended classses and implemented interfaces. You could argue that this is counter-intuitive, but I would respond that in general there is very little you do with a class where such information is missing: you cannot instantiate objects, you cannot use the metadata (the Class object) etc. With that background knowledge, I would say the behavior you see is expected.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload