英文:
Enum Class not visible in the same folder level
问题
我正在尝试从一个与我要访问它的类位于同一文件夹级别的单独文件中访问枚举类型。
以下是这两个文件:
Number.java:
public enum Number {
ONE, TWO, THREE
}
mainClass.java:
public class mainClass {
private Number numVar;
mainClass(Number num) {
numVar = num;
}
}
然而,mainClass无法将'Number'识别为有效的类型。具体来说,'Number'无法解析为类型。有任何想法是什么原因吗?
英文:
I'm trying to access an enum type from a separate file, which is in the same folder level as the class I'm trying to access it from.
These are the two files:
Number.java:
public enum Number {
ONE, TWO, THREE
}
mainClass.java:
public class mainClass {
private Number numVar;
mainClass(Number num) {
numVar = num;
}
}
However, mainClass doesn't recognise 'Number' as a valid type. Specifically 'Number' cannot be resolved to a type. Any idea why?
答案1
得分: 3
Number
是Java中的一个标准类。您应该重新命名您的枚举或者通过以下方式引用它:
private you_package.Number numVar;
但是我建议您重新命名您的枚举,并且不要将任何类或枚举命名为标准类的名称。这是官方文档链接。
英文:
Number
is a standard class in Java.
You should rename your Enum or reference it through
private you_package.Number numVar;
But I suggest you to rename you Enum and never name any class/enum as a standard one. Here's the official documentation of this class.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论