简体   繁体   中英

How can I reference Java files without packages?

DIR 1
  File A
    Class Y

DIR 2
  File B
    Class X implements Y

So let's say I have Class Y, in File A, which I want to use in file B. Is this possible? In a sense I'm asking if I can do this without packages, maybe something like.

using ../FileA.Y

This seems like a weird and stupid question, and I agree. But from my assignment spec it states, and I quote

Please put the submissions for each task into separate directories. Each directory should contain all files relevant for the task, in particular for compilation.

As well as

Please do not use Java's package construct.

A file from task 1 directory is required in task 2. And it seems idiotic to copy and paste a file.

Sure you can, so long as both DIR 1 and DIR 2 are added as source directories when you compile them. Once you do that, they are both placed in the root of the clasapath, and you can refer to one in the other directly without requiring the package name (in fact, you won't even import the referenced class).

Just be sure to name the two classes differently.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM