Reuse of identifier names in subscopes leads to obscuration or shadowing. The identifiers in the current scope render those defined elsewhere inaccessible. Although the Java Language Specification clearly resolves any syntactic ambiguity arising from obscuring or shadowing, such ambiguity burdens code maintainers, especially when code requires access to both the original named entity and the inaccessible one. The problem is exacerbated when the reused name is defined in a different package.
According to [§6.3.2, "Obscured Declarations,"|http://java.sun.com/docs/books/jls/third_edition/html/names.html#6.3.2] of the _Java Language Specification_ \[ [JLS 2005|AA. References#JLS 05]\], Wiki Markup
A simple name may occur in contexts where it may potentially be interpreted as the name of a variable, a type, or a package. In these situations, the rules of 6.5 specify that a variable will be chosen in preference to a type, and that a type will be chosen in preference to a package.
...
C++ Secure Coding Standard: DCL01-CPP. Do not reuse variable names in subscopes
Bibliography
...
[[JLS 2005AA. References#JLS 05]] | http://java.sun.com/docs/books/jls/third_edition/html/names.html#6.3.2] | ]]></ac:plain-text-body></ac:structured-macro> | |
| |||
| |||
| §14.4.3, "Shadowing of Names by Local Variables"<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="bf2897e6-123c-4622-996d-25615072806e"><ac:plain-text-body><![CDATA[ | ||
[[Bloch 2005AA. References#Bloch 05]] | Puzzle 67: All Strung Out | ]]></ac:plain-text-body></ac:structured-macro> | <ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="c5a99d24-7161-4a5a-9068-3f3575dad83c"><ac:plain-text-body><![CDATA[ |
[[Bloch 2008AA. References#Bloch 08] ] | Item 16: Prefer interfaces to abstract classes | ]]></ac:plain-text-body></ac:structured-macro> | <ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="d6bbdc4b-54c6-46e7-ad2a-c5e599858b33"><ac:plain-text-body><![CDATA[ |
[[Kabanov 2009AA. References#Kabanov 09]] |
| ]]></ac:plain-text-body></ac:structured-macro> | <ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="c64ac7fe-d4f0-437f-9275-d63cebcc8b95"><ac:plain-text-body><![CDATA[ |
[[Conventions 2009AA. References#Conventions 09]] | 6.3 Placement | ]]></ac:plain-text-body></ac:structured-macro> | <ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="643d96bc-2c96-4de4-b165-6a9a03c07456"><ac:plain-text-body><![CDATA[ |
[[FindBugs 2008AA. References#FindBugs 08]] | ]]></ac:plain-text-body></ac:structured-macro> |
...
DCL62-J. Minimize the scope of variables 01. Declarations and Initialization (DCL) DCL16-J. Do not reuse public identifiers from the Java Standard Library