Thread t = new Thread(new Runnable() { public void run() {} });
我希望以这种方式创建一个线程。如果可能的话,我如何将参数传递给
run
方法?
编辑:为了让我的问题更具体化,请考虑以下代码片段:for (int i=0; i< threads.length; i++) {
threads[i] = new Thread(new Runnable() {public void run() {//Can I use the value of i in the method?}});
}
根据Jon的回答,这个方法行不通,因为i没有被声明为
final
。