我有静态变量的问题我有 2 个类:
public class Test2 {
public static boolean bool;
public static void main(String[] args) {
// TODO Auto-generated method stub
bool = true;
int run=0;
while (bool==true) {
System.out.println("Test 2 "+run);
System.out.println(bool);
run++;
}
}
public static void setBool(boolean temp){
bool = temp;
}
}
和
public class Test3 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Test2.bool = false;
}
}
问题是当我运行 Test2 来执行循环,然后我运行 Test3 来终止 Test2 的循环但它不起作用。
如何通过 Test3 更改 Test2 的静态变量?