public class testFinal
{
public static void main(String[] args)
{
// TODO Auto-generated method stub
int[] test1 = {1,2,3};
change(test1);
System.out.println(":"+test1[0]+":"+test1[1]+":"+test1[2]);
testFinal testFinal = new testFinal();
people p = testFinal.new people();
p.setAge(10);
changeAge(p);
System.out.println(p.getAge());
}
private static void changeAge(final people p)
{
// TODO Auto-generated method stub
//final 只是可以防止重新new,但是无法防止set
// p = new testFinal().new people();
p.setAge(100);
}
private static void change(int[] test1)
{
// TODO Auto-generated method stub
//想想内存里就明白了,
test1[0] = 1000;
//new的话,是创建了新的地址,这里的test1指向新的地址,原来的test1指向原来的地址
test1 = new int[] {100,200,300};
}
class people {
int age;
public void setAge(int age){
this.age = age;
}
public int getAge(){
return age;
}
}
}
{
public static void main(String[] args)
{
// TODO Auto-generated method stub
int[] test1 = {1,2,3};
change(test1);
System.out.println(":"+test1[0]+":"+test1[1]+":"+test1[2]);
testFinal testFinal = new testFinal();
people p = testFinal.new people();
p.setAge(10);
changeAge(p);
System.out.println(p.getAge());
}
private static void changeAge(final people p)
{
// TODO Auto-generated method stub
//final 只是可以防止重新new,但是无法防止set
// p = new testFinal().new people();
p.setAge(100);
}
private static void change(int[] test1)
{
// TODO Auto-generated method stub
//想想内存里就明白了,
test1[0] = 1000;
//new的话,是创建了新的地址,这里的test1指向新的地址,原来的test1指向原来的地址
test1 = new int[] {100,200,300};
}
class people {
int age;
public void setAge(int age){
this.age = age;
}
public int getAge(){
return age;
}
}
}