Java different package name the same class name conflict can only rename the class name?

< H2 > scenario 1 < / H2 >

suppose:

one
    Test.java
two
    Test.java
App.java

such a directory structure. App.java is the entry, and the content is as follows:

//  one.Test  two.Test 
import one.Test;
import two.Test;

public class App {
    public static void main(String[] args){
        //  one.Test 
        //  two.Test 
    }
}

in the case of the above, how to solve the problem of different package names with the same class name? Can we only rename the conflict class? Or do you quote it in a full-path way?

Jul.29,2021

you have said a good solution, and another thing that is not very good is that custom classloader


custom classloader can be solved.


because you have two identical object names, both Test, and import, when the java compiler does not know which one you are calling. So if two classes have the same name, one uses the import, and the other uses the full name. There is no problem with import for different class names.


Java does not have renaming such as using , typedef , so you can only write the package name in its entirety.

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b35c60-2bfb4.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b35c60-2bfb4.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?