Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

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="c38b09a628c44708-132e5e76-4a08458f-8e5580e1-66fd92e5fc692d540ea92319"><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>

 

§6.3.1, Shadowing Declarations

 

§7.5.2, Type-Import-on-Demand Declaration

 

§14.4.3, Shadowing of Names by Local Variables

<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="da87deadb30d90b7-10a33cfe-44284ba3-a26bbd36-b5dea49316416dd7335aef4a"><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="4a92c24529157a21-e7ec0bb2-47684847-b1b4a2da-6b843c0ee51f04a62d75f423"><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="bc3f070fcc84471f-626cf97f-49454e65-9212ae98-138085988cf76b9a3b45dc34"><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>

...