1. Replace the constructor with a static factory method.
2. Consider using the builder when you encounter multiple parameter constructors.
3. Strengthen the singleton with a private constructor or a U.S. drama type.
4. The ability to harden non-instancing through a private constructor.
5. Avoid creating unnecessary objects.
Try to use string str = "xxx" instead of string str = new string ("xxx");
6. Eliminate expired object references.
7. Avoid using the finalization method.
When the finalization method is called or whether it is called is indeterminate.
8. Overriding equals is subject to the general rules.
Reflexive, symmetric, transitive, consistent, non-nullability (x.equals (NULL) return FALSE) is required.
The timestamp in the Java library extends the date, adding the nanoseconds domain, and the equals implementation violates the symmetry. You cannot use timestamp and date in the same collection, which can cause incorrect behavior.
The trick to raising equals: a. Use the = = operation to check if a parameter is a reference to this object, which is worth doing if the comparison operation can be expensive. B. Use the instanceof operation to check if the parameter is of the correct type. C. Convert the parameter to the correct type. D. Overriding equals is always to overwrite hashcode. E. Do not attempt to make the Equals method too intelligent. F. Do not replace object objects in the equals declaration with other types.
9. Always overwrite equals when hashcode is overwritten.
Summary of the essentials of effective Java