Java Reference
In-Depth Information
< Day Day Up >
9. Name Reuse
This section concerns the many forms of name reuse possible in Java. The overriding prescription
is: Avoid name reuse except for overriding. See also "A Glossary of Name Reuse" on page 180.
9.1. It is easy to overload when you intend to override
Prescription: Mechanically copy the declaration of each superclass method that you intend to
override; better yet, let your IDE do it for you.
If you are using release 5.0 or a later release, use the @Override annotation.
References: Puzzle 58 .
9.2. Overload-resolution rules are not obvious
Prescription: Avoid overloading.
Provide static factories rather than multiple constructors.
If two methods in your API are both applicable to some invocation, ensure that both methods have
the same behavior on the same actual arguments.
References: Puzzles 11 , 46 , and 74 ; [JLS 15.12.2] and [EJ Items 1 and 26].
9.3. Programs that hide entities are difficult to understand
Prescription: Avoid hiding.
References: Puzzles 66 , 72 , 73 , and 92 ; [JLS 8.3, 8.4.8.2, 8.5].
9.4. Programs that shadow entities are difficult to understand
Prescription: Avoid shadowing.
Do not reuse names from java.lang.Object in public APIs.
Don't try to use static import on a name that is already defined.
References: Puzzles 71 , 73 , 79 , and 89 ; [JLS 6.3.1, 15.12.1].
9.5. Programs that obscure entities are difficult to understand
 
 
Search WWH ::




Custom Search