⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 attack.java

📁 effective-java中文英文版,大师人物写的
💻 JAVA
字号:
// 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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -