[英]Importing classes inside JAR files that are in the default package
How do I use Queue here? 我如何在这里使用Queue?
I can't get the import to work because Queue.class is not in a package. 我无法让导入工作,因为Queue.class不在包中。
I have tried everything in this universe, and more. 我已经尝试过这个宇宙中的一切,等等。
http://i.stack.imgur.com/AFrrc.jpg
http://i.stack.imgur.com/AFrrc.jpg
Your Queue
class is under unnamed package (refer JLS ). 您的
Queue
类位于未命名的包中(请参阅JLS )。 It can't be imported. 它无法导入。 Also, it's bad practice.
而且,这是不好的做法。
You have two options 你有两个选择
Move your own code to unnamed package. 将您自己的代码移动到未命名的包。 Theoretically, both of them being in same package, you will not need to import
Queue
as it's class-name is suffice to find out the class. 从理论上讲,它们都在同一个包中,你不需要导入
Queue
因为它的类名就足以找到这个类。
Use JarJar - a tool to repackage your Jar files. 使用JarJar - 重新打包Jar文件的工具。 Repackage the Jar containing the
Queue
class and move the unnamed package to a sensible package name. 重新打包包含
Queue
类的Jar,并将未命名的包移动到合理的包名称。 Use Fully Qualified Class Name (FQCN) to import. 使用完全限定类名(FQCN)导入。
I would suggest to use packages and go for option 2. 我建议使用包,然后选择选项2。
Edit 1 : also see this What's the syntax to import a class in a default package in Java? 编辑1 :也看到这个在Java中的默认包中导入类的语法是什么?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.