Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: added mention of source code auditors

Reuse of identifier names in subscopes leads to obscuration or shadowing. The reused 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 and source code auditors, 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.

...

No identifier should obscure or shadow another identifier in a containing scope. For instanceexample, a local variable should not reuse the name of a class field or method or the class name or package name. Similarly, an inner class name should not reuse the name of an outer class or package.

...