Launching single file source code program - "error: class found on application class path"
jonathan.gibbons at oracle.com
Mon Jun 18 21:42:52 UTC 2018
On 6/18/18 2:33 PM, Attila Szegedi wrote:
> On 2018. Jun 18., at 19:52, Jonathan Gibbons <jonathan.gibbons at oracle.com> wrote:
>> On 06/17/2018 03:56 AM, Jaikiran Pai wrote:
>>> The /tmp/foo-bar directory now consists of A.class and A.java. I then went ahead and (tried) to launch the A.java using the new feature as previously:
>>>> java A.java
>>> I now get this error message:
>>> error: class found on application class path: A
>>> 2. Why is this an error? Is it intentional?
>> This is the intended behavior, to avoid the ambiguity of having the class on the classpath (which defaults to the current directory) and the internally-compiled class generated from the source file.
> Is this really ambiguous?
> If the user runs “java A.java”, their intent is clearly to run the source code file. The file name is explicitly spelt out in the command.
> If the user runs "java A”, then – if only from a purely backwards-compatible perspective – it should run the precompiled class; same way “java” command worked before this feature existed. I can see how one might argue user's intent was ambiguous in this case, though. (But then, it isn't the case original poster asked about.)
Yes, we wanted to avoid any confusion between the possibility of the
class being on the classpath and being specified as a source file.
More information about the jdk-dev