DEV Community


Discussion on: Can I import local class files in Java, like you can Python?

clo profile image
Christopher Lowenthal

It's been a while, so I may be completely off.
But files in the same folder are in the same namespace.
If you need something outside of the normal folder structure, it's possible to load a compiled bytecode file.
It's also possible to load text from a file, or anywhere, and compile it in real time.

I'm recalling from work on a game engine 12ish years ago. So it may even be easier now.

baenencalin profile image
Calin Baenen Author

It's not in the same folder. customclass is in a folder below the package.

Like this:

package: // I want to import files from subpackage here.
        // Files....
Enter fullscreen mode Exit fullscreen mode
clo profile image
Christopher Lowenthal

I'm also recalling that it's possible to create your own loader that determines the rules of where to find classes.
IIRC you could make it so your code above works, but not sure it's worth the effort.

Alrighty now my head hurts from digging that deep into past projects.