如何从默认包中导入类 [英] How to import a class from default package
问题描述
I我正在使用Eclipse 3.5,我创建了一个包含一些包结构和默认包的项目。我在默认包中有一个类 - Calculations.java ,我想在任何包中使用该类(例如在 com.company.calc
)。当我尝试使用默认包中的类时,它给了我一个编译器错误。它无法识别默认包中的类。问题出在哪里?
I am using Eclipse 3.5 and I have created a project with some package structure along with the default package. I have one class in default package - Calculations.java and I want to make the use of that class in any of the package (for instance in com.company.calc
). When I try to make the use of the class which is in the default package, it's giving me a compiler error. It's not able to recognise the class in default package. Where is the problem?
Calculations.java - 源代码
Calculations.java - source code
public class Calculations {
native public int Calculate(int contextId);
native public double GetProgress(int contextId);
static {
System.loadLibrary("Calc");
}
}
我不能把我的班级放在任何其他套餐中。这个类有一些在Delphi中实现的本机方法。如果我将该类放在任何文件夹中,我将不得不对我想要避免的DLL进行更改(实际上 - 我不能)。这就是为什么我把我的类放在默认包中。
I can't put my class in any other package. This class has some native methods which are implemented in Delphi. If I put that class in any of the folders, I will have to make changes to that DLL which I want to avoid (really - I can not). That's why I put my class in the default package.
推荐答案
来自 Java语言规范:
从未命名的包中导入类型是一个编译时错误。
It is a compile time error to import a type from the unnamed package.
你必须访问通过反思或其他间接方法进行分类。
You'll have to access the class via reflection or some other indirect method.
这篇关于如何从默认包中导入类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!