EffectivejavaThird edition The latest recommendations mainly increase the LAMDA expression and flow recommendations,
The second edition of XXX is not.
Create and Destroy objects
1 Consider replacing the constructor with a static factory method
2 consider replacing with builder (builder) When multiple constructor parameters are encountered
3 Hardening a singleton property with a private constructor or enumeration type
4 ability to harden non-instancing through private constructors
5 Dependency Injection Priority hard Connect resource @
6 Avoid creating unnecessary objects
7 Elimination of expired object references
8 Avoid using finalization methods and cleaner
9 Try-with-resources Priority try-finally @
Two common methods for all objects
when he wrote equals , he complied with the general rules.
When you write the Equals, always write hashcode.
always overwrite toString
carefully overwrite clone
Consider implementing the comparable interface
Three classes and interfaces
minimum visibility of classes and members
Use Access method instead of public domain in public class
The minimum variability is
The combination is better than inheritance
Either design and provide documentation for inheritance, or disallow inheritance
Interface is better than abstract class
21 designing interfaces for future generations
The interface is only used to define the type
The class inheritance is better than the label class
the static class is preferred instead of the non-static
Limit the source file to a single top-level class @
Four -generic
Do not use native types
Elimination of non-inspected warnings
list is better than array
Priority is given to generics
First, the generic method is considered
Use bounded wildcard to enhance API flexibility
32 careful combination of generics and variable parameters @
Prioritize type-safe heterogeneous containers
Five enumerations and annotations
use enum instead of int constant
Replace ordinal with instance field
using enumset instead of bit field
PNS replaces ordinal index with Enummap
The use of interfaces to simulate extensible enumerations
The more than the naming pattern of the comments
Unified use of Override annotations
To define a type with a tag interface
Six lambda expressions and streams
A lambda expression is better than an anonymous class
43 method Reference is better than lambda expression
44 preferential use of standard functional interfaces
45 use the flow carefully
46 priority use of function without side effects in stream
47 return type Flow Precedence collection
48 be careful when creating parallel streams
Seven methods
Check the validity of the parameters
A protective copy when needed
Careful design method signature
Use heavy loads with caution
carefully variable parameters
To return an empty collection or array instead of null
55 Cautious return Optionals @
All document annotations for all exported API elements
Eight General program design
Minimized local variable scope
+/-Each is superior to the traditional for loop
Learn about and use class libraries
If you need a precise answer, avoid using float and double
The basic type is better than the boxed type
If other types are more appropriate, avoid using String
Careful String connection Performance
The object is referenced by interface
The interface is better than the reflection
Use local methods with caution
cautious optimization
To comply with the universal naming conventions
Nine anomalies
Only use exceptions for exception cases
Use a run-time exception for a programmatic error with a recoverable condition using a inspected exception
Avoid the need to use a inspected exception
The use of standard exceptions is preferred
The exception that throws with the abstract corresponding to the
Each method throws an exception to have a document
The details contain information about the failed capture.
The effort to keep the failure atomic
Don't Ignore exceptions
Ten Concurrent
Synchronize access to shared mutable data
Avoid over-synchronization
Executors,task,stream is better than thread @
The bayi concurrency tool is better than wait and notify
A thread-safe documentation of the
Delay initialization with caution
Do not rely on thread scheduler
Eleven
85 Consider other alternatives that are better than Java serialization @
The use of custom serialization forms is considered
Meticulous implementation of Serializable interface
How to write ReadObject method in the protection of the
For instance control, enumeration is better than Readresolve
Consider a serialization agent to replace a serialized instance
Effectivejava Third Edition (latest recommendation)