attack.java
来自「java 进阶专用。」· Java 代码 · 共 25 行
JAVA
25 行
// Attack the internals of a Period instance.
import java.util.*;
public class Attack {
public static void main(String args[]) {
// First attack, thwarted by defensive copy in constructor - Page 123
Date start = new Date();
Date end = new Date();
Period p = new Period(start, end);
System.out.println(p);
end.setYear(78); // Modifies internals of p!
System.out.println(p);
System.out.println();
// Second attack, thwarted by defensive copy in accessors - Page 124
start = new Date();
end = new Date();
p = new Period(start, end);
System.out.println(p);
p.end().setYear(78); // Modifies internals of p!
System.out.println(p);
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?