今天在学习泛型时,在泛型的构造方法使用中遇到了问题,如下
class Con<T>
{
private T value;
public Con(T value) {
this.value=value;
}
public T getValue() {
return value;
}
public void setValue(T value) {
this.value = value;
}
}
public class GenericDemo4 {
public static void main(String[] args) {
Con<String> con = new Con<String>("在构造方法中使用泛型");
System.out.println(con.getValue());
}
}
首先定义了一个名为Con的类,并在构造方法中使用了泛型。然后Eclipse报了个错,错误信息为:A class file was not written. The project may be inconsistent, if so try refreshing this project and building it
查了一些答案,发现原因如下
下面是其他的一些保留字,在Windows下面都不能创建。注重,不许分大小写。Con,con,CON 都不可以!
con是操作系统保留的一个设备名字,还有很多设备名都不能拿来用,如下:
The following reserved device names cannot be used as the name of a file: CON, PRN, AUX, CLOCK$, 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 by an extension (for example, NUL.tx7).
所以在Windows系统下,将类名Con改为其他名字即可,在苹果电脑下则不会有此问题
原文链接:http://www.cnblogs.com/lostyue/archive/2011/07/13/2105190.html