这是我的代码:
// This is the bug - this works.
String[] lst = {"desk", "pencil"};
String lst0 = lst[0];
System.out.println("path: " + lst[0]);
System.out.println("result: " + root.getDirectory(lst0).getFileName());
// This is the bug - this doesn't work.
String[] ef = "desk/pencil".split("/");
String ef1 = ef[0];
System.out.println("path: " + ef1);
System.out.println("result (without getFileName): " + root.getDirectory(ef1));
但是在第二种情况下,函数没有被正确调用,因为编译器认为ef [0]与lst [0]不同,尽管两者都是字符串。我假设这是因为列表拆分导致的数组。有没有办法解决/解决这个问题?