0

I am working on a legacy Java app and am investigating why there are duplicate classes in 2 of the projects, used in the workspace.

So the classes from project1 and project2 are both in com.example.SomeClass - the package name is the same, as well as the class name. That is all that is contained in the import statement, I cannot state from which package I want to import it. However, in the Java Build Path tab in Eclipse I can see that both project1 and project2 are added.

So how does it decide if it will import project1.com.example.SomeClass, or from project2.com.example.SomeClass?

ZINE Mahmoud
  • 1,272
  • 1
  • 17
  • 32
Rivfader
  • 59
  • 6

1 Answers1

0

Class precedence for different classes sharing the same package and name relies on the default ClassLoader (unless you set a different ClassLoader). This is implementation-specific (it depends if you're using e.g. OpenJDK, Oracle JDK ...etc).

Usually you'd expect that it would use the precedence defined at the classpath, but this is not mandatory.