testconst.java.orig
来自「Java安全性编程实例,解压看说明」· ORIG 代码 · 共 33 行
ORIG
33 行
public class TestConst{
final int x[ ]={1,2,3};
final NewConst y=new NewConst();
public static void main(String args[] ){
TestConst t=new TestConst( );
t.go( );
int[ ] x1=t.x;
System.out.println("The code with problem");
for(int i=0;i<x1.length;i++){
System.out.println(x1[i]);
}
NewConst x2=t.y;
System.out.println("The code without problem");
for(int i=0;i<x2.getConst().length;i++){
System.out.println(x2.getConst()[i]);
}
}
void go(){
x[0]=20;
y.getConst()[0]=20;
}
}
class NewConst{
private final int x[ ]={1,2,3};
public final int[ ] getConst( ){
int [] s=(int []) x.clone();
return(s);
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?