展开全部
在匿名类中,使用final修饰变量(其实基础类型也是被62616964757a686964616fe4b893e5b19e31333365653330修饰了)@Test
public void test1() {
int app = 12;
final Circle circle = new Circle(123);
String string = "";
new Thread(new Runnable() {
@Override
public void run() {
System.out.println(app);
System.out.println(string);
circle.setRadius(12);
System.out.println(circle);
}
}).start();
}
2. 当单独定义了线程通过传参的方式
1. 通过构造方法传参
2. 通过线程内部的方法传参
class ThreadA implements Runnable {
private Circle circle;
// 方法1
public ThreadA(Circle circle) {
this.circle = circle;
}
// 方法2
public ThreadA() { }
@Override
public void run() {
// TODO Auto-generated method stub
System.out.println(circle.toString());
}
// 方法2
public void setCircle(Circle circle) {
this.circle = circle;
}
}
3. 修改错误,在上的回调函数中应该是 `Integer... numbers`