我目前正在研究一个小型Java应用程序,并遇到问题。我创建了两个不同的变量,但是在我运行代码之后,第一个变量获得了与第二个变量相同的值。他们应该是不同的。获得相同值的两个不同变量
这里是我的自定义文件类:
public class MyFile {
private static String path;
private static String name;
private static final String FILE_SEPARATOR = "/";
public MyFile(String path) {
System.out.println(path);
this.path = "";
this.name = "";
this.path = /*FILE_SEPARATOR*/path;
String[] dirs = path.split(FILE_SEPARATOR);
this.name = dirs[dirs.length - 1];
}
public static String getPath() {
return path;
}
public static String getName() {
return name;
}
public String toString() {
return "Path: " + path + ", Name: " + name;
}
}
这里我使用的变量:
MyFile modelFile = new MyFile("res\\model.dae");
MyFile textureFile = new MyFile("res\\diffuse.png");
System.out.println(modelFile.toString());
System.out.println(textureFile.toString());
太感谢你了 – Simagdo
欢迎您:) – davidxxx