override equals

Effective Java 的笔记,代码、英语原文为主,批注、翻译为辅。 Item 10: Obey the general contract when overriding equals 覆盖 equals 方法时请遵守通用约定 Not to override the equals method 1. Each instance of the class is inherently unique. This is true for classes such as Thread that

Memory Leaks + Garbage Collect

Effective Java 的笔记,代码、英语原文为主,批注、翻译为辅。 Item 7: Eliminate obsolete object references 消除过时的对象引用 Incorrect Version 一个简单的Stack实现的例子: 1 2 3 4 5 6 7 8 9 10 11 12 13

Prefer try-with-resources to try-finally

Effective Java 的笔记,代码、英语原文为主,批注、翻译为辅。 Item 9: Prefer try-with-resources to try-finally 使用 try-with-resources 优于 try-finally try-finally 1 2 3 4 5 6 7 8 9 // try-finally - No longer the best way to close resources! static String firstLineOfFile(String path) throws IOException { BufferedReader br = new BufferedReader(new FileReader(path));