可能的重复项:need-help-returning-object-in-thread-run-method
你好。我有一个实现runnable的类,我有一个List,存储用该类的不同对象实例化的Thread。给定运行底层对象的线程对象,我如何访问它们的属性?下面是一个示例:
public class SO {
public static class TestRunnable implements Runnable {
public String foo = "hello";
public void run() {
foo = "world";
}
}
public static void main(String[] args) {
Thread t = new Thread(new TestRunnable());
t.start();
//How can I get the value of `foo` here?
}
}
https://stackoverflow.com/questions/2300579
复制相似问题