package test;
public class TestFinal
{
//只有定义成 final User user 才不会报错为什么?
public void test( User user)
{
(new Thread()
{
public void run()
{
System.out.println("user.name-->"+user.name);
}
}
).start();
}
public static void main(String[] args)
{
User user=new User();
user.setId(007);
user.setName("zhaoyang");
TestFinal testFinal=new TestFinal();
testFinal.test(user);
}
}
class User
{
String name=null;
int id;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
}