Reputation: 29885
I have two classes that have the same class name and use the same package name. However, the two class files are located in different directories. One other thing that is different between the two is that each class has methods in it that do not appear in the other. In essence, I want to split the methods into two separate files using the same name but different folders.
Theoretically I would think that this is possible because the Java compiler does maintain the directory structure when it builds the output. So during runtime, if a method is called in the class, perhaps Java would look to find the method in whichever file had the method.
Is this even possible? I'm using IntelliJ and it seems to only let me pick one of the class files but not both when it needs to resolve a method.
Upvotes: 2
Views: 3496
Reputation: 11
If the classes are in different package, it is possible by adding Qualifier.
@Qualifier("yourClassQualifierName1")
@Qualifier("yourClassQualifierName2")
Upvotes: 0
Reputation: 97338
No, this is not possible. Java will not "look to find the method", it will resolve a single .class file by fully-qualified name, look for the method there, and throw an exception if it's not there. You need to find a different way to split your code into multiple classes.
Upvotes: 4