Implied readability: calling toString()

Jochen Theodorou blackdrag at
Fri May 27 12:18:56 UTC 2016

On 27.05.2016 13:39, Sander Mak wrote:
> I'm running into the following compilation error (build
> $ javac -modulesourcepath src -d out $(find . -name '*.java')
> .src/test/client/ error: toString() in Object is defined in an inaccessible class or interface
>        repository.findText(id).toString();
> Besides the fact that the error message is somewhat confusing (how would toString() in Object ever be inaccessible?), this example raises a question on implied readability for me.
> In this case, repository.findText() returns a type Text that normally requires implied readability. I deliberately omitted the 'public' from the corresponding requires clause, since I thought that calling toString() (or equals/hashCode) would be possible without having readability on the actual type. In the end it's just an invokevirtual on j.l.Object, right? Am I missing something here? It works fine when adding back the 'public' to the requires clause, obviously.

It is an invokevirtual on Object only if the signature of findText(id) 
returns Object. If the method is declared to return Server then it is an 
invokevirtual on Server instead and requires the class Server to be 

bye Jochen

More information about the jigsaw-dev mailing list