...
| Code Block | ||
|---|---|---|
| ||
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="44c9c130637f7178-2fd91159-4ded41fa-be14a789-12bff9ce2157d34617dd6783"><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> |
| |||||
| |||||
| |||||
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="0c8fd7efeddbab29-93ddb61f-4e1b4cac-95679121-79c8affa81326a9176fbe179"><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="e48454382d81972d-1d0e50a1-48694024-8c6087c9-e185b117ed4fc1ee4c5cc2c5"><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="bf9e4de72ca6b300-debd1d12-42cf48c2-9ee88acf-a15dcf019fe2788b46443a05"><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> |
...