为总的菜鸟问题道歉,但任何人都可以解释match
在 for-each 循环以下列方法完成后的值发生了什么?
尝试编译会产生警告:variable match might not have been initialised
.
public void listMatching(String searchString) {
boolean match;
for(String filename : files) {
if(filename.contains(searchString)) {
System.out.println(filename);
match = true;
}
else {
match = false;
}
}
if(match == false) {
System.out.println("No matches found for " + searchString);
}
}