Versions Compared

Key

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

...

Code Block
bgColor#FFcccc
class Vector {
  private int val = 1;

  public boolean isEmpty() {
    if (val == 1) {   // compares with 1 instead of 0
      return true;
    } else {
      return false;
    }
  }
  // other functionality is same as java.util.Vector
}

// import java.util.Vector; omitted

public class VectorUser {
  public static void main(String[] args) {
    Vector v = new Vector();
    if (v.isEmpty()) {
      System.out.println("Vector is empty");
    }
  }
}

...

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#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="c3b49d5292df3f9b-600cc677-4ef549df-8d56966d-20de6400335da72fd912b3e5"><ac:plain-text-body><![CDATA[

[[JLS 2005

AA. Bibliography#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="fa5a22ff63c86607-178064ac-4003487f-b05ca3be-f90e34a20dae76683ee05a15"><ac:plain-text-body><![CDATA[

[[FindBugs 2008

AA. Bibliography#FindBugs 08]]

]]></ac:plain-text-body></ac:structured-macro>

<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="e3350fb703f8e286-0796992e-44ff4af6-95459f26-58300ba7445a515b0153b72a"><ac:plain-text-body><![CDATA[

[[Bloch 2005

AA. Bibliography#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="837d81139bb71240-97e0da27-4863448f-92f597e8-75a87d0d34097e5f23b100f0"><ac:plain-text-body><![CDATA[

[[Bloch 2008

AA. Bibliography#Bloch 08]]

Item 16, Prefer interfaces to abstract classes

]]></ac:plain-text-body></ac:structured-macro>

...