...
| Wiki Markup |
|---|
When a developer uses an identifier that has the same name as a public class, such as {{Vector}}, a subsequent maintainer might be unaware that this identifier does not actually refer to {{java.util.Vector}} and might unintentionally use the custom {{Vector}} rather than the original {{java.util.Vector}} class. The custom type {{Vector}} can [shadow|BB. Glossary#shadow] a class name from {{java.util.Vector}}, as specified by the JLS, [§6.3.2, "Obscured Declarations"|http://java.sun.com/docs/books/jls/third_edition/html/names.html#6.3.2] \[[JLS 2005|AA. Bibliography#JLSReferences#JLS 05]\]. This can result in unexpected program behavior. |
| Wiki Markup |
|---|
Well-defined import statements can resolve these issues. However, when reused name definitions are imported from other packages, use of the _type-import-on-demand declaration_ (see the JLS, [§7.5.2, "Type-Import-on-Demand Declaration"|http://java.sun.com/docs/books/jls/third_edition/html/packages.html#7.5.2] \[[JLS 2005|AA. Bibliography#JLSReferences#JLS 05]\]) can complicate a programmer's attempt to determine which specific definition was intended to be used. Additionally, a common practice that can lead to errors is to produce the import statements _after_ writing the code, often via automatic inclusion of import statements by an IDE. This creates further ambiguity with respect to the names. When a custom type is found earlier than the intended type in the Java include path, no further searches are conducted. Consequently, the wrong type is silently adopted. |
...
| Wiki Markup |
|---|
When the developer and organization control the original shadowed class, it may be preferable to change the design strategy of the original in accordance with Bloch's _Effective Java_ \[[Bloch 2008|AA. Bibliography#BlochReferences#Bloch 08]\], Item 16, _Prefer interfaces to abstract classes_. Changing the original class into an interface would permit class {{MyVector}} to declare that it implements the hypothetical {{Vector}} interface. This would permit client code that intended to use {{MyVector}} to remain compatible with code that uses the original implementation of {{Vector}}. |
...
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="21f3ec83cf2c147a-63bf9974-4d774788-8a42ac18-d6d4da4626b5386293566164"><ac:plain-text-body><![CDATA[ | [[JLS 2005 | AA. Bibliography#JLS References#JLS 05]] | [§6.3.2, Obscured Declarations | http://java.sun.com/docs/books/jls/third_edition/html/names.html#6.3.2] | ]]></ac:plain-text-body></ac:structured-macro> |
| |||||
| |||||
| |||||
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="d978f2ec984f1c0c-3284b601-4605499a-b0649268-9fa7c028dbf976c43fec1f7a"><ac:plain-text-body><![CDATA[ | [[FindBugs 2008 | AA. Bibliography#FindBugs References#FindBugs 08]] | ]]></ac:plain-text-body></ac:structured-macro> | ||
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="bdb87ef373b0ac82-f04895a0-425447e9-83768781-0638569a696f2384e7337350"><ac:plain-text-body><![CDATA[ | [[Bloch 2005 | AA. Bibliography#Bloch 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="8709b18294fa643a-e358db39-4dac4da3-b3cc83c9-e29518aa4ef978ac4193ee8e"><ac:plain-text-body><![CDATA[ | [[Bloch 2008 | AA. Bibliography#Bloch References#Bloch 08]] | Item 16. Prefer interfaces to abstract classes | ]]></ac:plain-text-body></ac:structured-macro> |
...