简体   繁体   中英

Fully qualified class names for specific package?

是否可以为特定的软件包强制使用完全合格的类名?

You can't do that with the Java compiler. But there are several static source analysis tools out there that you could use.

You can force fully qualified class names for certain packages by disallowing import statements for those packages - in that case, the code using classes in these packages can only do so with fully qualified names.

For example, you can use the IllegalImport module in Checkstyle :

One of the examples on the page I linked above shows how you can disallow imports for certain packages:

To configure the check so that it rejects packages java.io.* and java.sql.*:

 <module name="IllegalImport"> <property name="illegalPkgs" value="java.io, java.sql"/> </module> 

Quoted from Checkstyle documentation

You can select the class name and press Ctrl + h 'in Eclipse or STS' and copy the Fully qualified class name

You can use * at the end of the package name instead of the class name to select all classes in this package

For Example: I have a class called Home in a package called com.example.test If I wanna to select only this class, the fully qualified class name will be com.example.test.Home If I have More than one class in this package and I wanna to select them all, the fully qualified classes name will be com.example.test.*

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