使用Windows等设备名称作为Java类名称 [英] Using Windows device name such as Con as Java class name
问题描述
我指的是我之前的问题但是这次我使用了java编译器并且编译器编译了输出 - 它给出了一个奇怪的输出。这次我使用这个
而不是 super
。
I am referring to my previous question but this time I used the java compiler and the compiler compiles the output- it gives a weird output. And this time I used this
instead of super
.
这是程序的代码。
class Con {
int x = 10;
Con() {
this(2);
System.out.println("x :" + x);
}
Con(int i) {
x = i;
System.out.println("x :" + x);
}
}
class DemoCon {
public static void main(String args[]) {
Con c1 = new Con();
}
}
您认为这里的问题是什么?这是Java中的错误吗?
What do you think is the problem here? Is this a bug in Java?
Java版本 - 1.6.0 JDK
Java version - 1.6.0 JDK
我用Eclipse运行程序而且有一个Class没有发现异常。
A.java
是文件名...我们进行了一次小编辑并创建了一个名为 A.java的公共类
也是,但结果是一样的。我们进一步发现问题在于编译器。
I used Eclipse to run the program and there is a Class not found exception.
A.java
is the file name... We did a minor edit and made a public class called A.java
too but the results are same. We further found out that the problem lies in the compiler.
推荐答案
在Windows上,似乎CON是保留名称,不能用于文件夹/目录或文件名。
On Windows it seems CON is reserved name and cannot be used for folders/directories or filenames.
以下
print "test" > Con.java
无效。
因此编译器无法创建Con.class并崩溃。
Therefor the compiler is unable to create your Con.class and crashes.
来自 MSDN :
请勿使用以下保留的设备为一个文件的名称的名称:
Do not use the following reserved device names for the name of a file:
CON,PRN,AUX,NUL,COM1,COM2,COM3,COM4,COM5,COM6,COM7,COM8,COM9,LPT1 ,LPT2,LPT3,LPT4,LPT5,LPT6,LPT7,LPT8和LPT9。同时避免使用这些名称,然后立即进行扩展;例如,不建议使用NUL.txt
CON, PRN, AUX, NUL, COM1, COM2, COM3, COM4, COM5, COM6, COM7, COM8, COM9, LPT1, LPT2, LPT3, LPT4, LPT5, LPT6, LPT7, LPT8, and LPT9. Also avoid these names followed immediately by an extension; for example, NUL.txt is not recommended
这篇关于使用Windows等设备名称作为Java类名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!