Java Reference
In-Depth Information
< Day Day Up >
8. Other Class- and Instance-Related Topics
This section concerns method invocation, method design, class design, and generic types.
8.1. There is no dynamic dispatch on static methods
Prescription: Never qualify a static method invocation with an expression; always use a type.
References: Puzzle 48 ; [JLS 15.12.4.4].
8.2. Inner classes are confusing
Prescription: Prefer static member classes to inner classes.
References: Puzzles 80 , 89 , 90 , and 92 ; [EJ Item 18].
8.3. Failure to make defensive copies destroys immutability
Prescription: Make defensive copies of input parameters and output values as required.
References: [EJ Item 24].
8.4. Implementing an interface affects the API of the implementing
class
Prescription: Do not implement an interface to gain unqualified access to its static fields.
Do not write an interface consisting solely of fields, a so-called constant interface .
In release 5.0 and later releases, use static import as a replacement for the Constant Interface
antipattern.
References: [EJ Item 17] and [Java-5.0] .
8.5. Using int constants as enum values is unsafe
Prescription: Use enum types or, if you are using a release before 5.0, implement Typesafe Enums.
References: [EJ Item 21].
8.6. Mixing raw and parameterized types weakens type checking
 
 
Search WWH ::




Custom Search