First, check the validity of the parameters
1, consider the limitations of the parameters, write the restrictions to the document, at the beginning of the method by explicit check to enforce these restrictions.
Second, if necessary, a protective copy
1. If a class has a mutable component that is obtained or returned from the client, the class must consider a protective copy of these components.
2, if the copy cost is high, the class can also trust his client, do not copy protection, but to document the description.
Third, careful design method signature
1, carefully choose the name of the method: abide by the norms, to maintain the same style.
2, do not seek to provide convenient methods.
3. Long-coded parameter list
A, a method decomposed into multiple methods
B, create auxiliary classes, save the grouping of parameters.
C. Using the builder mode
4. For parameter types, use interfaces rather than classes to prioritize
5. For the Boolean parameter, use the enumeration type of the two element first.
Iv. using heavy loads with caution
1. Calls to overloaded methods are made at compile time. The choice of the override method is to make a decision at run time.
2. Try not to export multiple overloaded methods with the same number of parameters.
3. Do not overload a method with variable parameters
Five, cautious use of variable parameters
Returns an array or collection of 0 lengths, not NULL
1. Methods that return types to arrays or collections should return a 0-length array or collection instead of NULL.
Vii. Writing documentation comments for all exported API elements
Effective Java Reading notes six methods