J
Joona I Palaste
I've seen a few casts in the Java code some of my colleagues write I
think are totally needless. For example, various upcasts. For example:
public class Core {
public void update(Component c) { /* ... */
}
}
public abstract class Component { /* ... */
}
public class MagicComponent extends Component { /* ... */
public void doThings() { /* ... */
new Core().update((Component)this);
}
}
That I could think would be explained by reminding people (who are
too stupid to look at the class declaration) that MagicComponent
extends Component, but then there are casts that cast an object to
the class it already is:
Item i = new Item();
component.add((Item)i);
and I once even saw this:
String error_notInitialized = (String)"Not initialized.";
What's the point in *that*?
(All code above has been paraphrased. The syntax is preserved but
the semantics aren't. The real code is under NDA.)
--
/-- Joona Palaste ([email protected]) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"The large yellow ships hung in the sky in exactly the same way that bricks
don't."
- Douglas Adams
think are totally needless. For example, various upcasts. For example:
public class Core {
public void update(Component c) { /* ... */
}
}
public abstract class Component { /* ... */
}
public class MagicComponent extends Component { /* ... */
public void doThings() { /* ... */
new Core().update((Component)this);
}
}
That I could think would be explained by reminding people (who are
too stupid to look at the class declaration) that MagicComponent
extends Component, but then there are casts that cast an object to
the class it already is:
Item i = new Item();
component.add((Item)i);
and I once even saw this:
String error_notInitialized = (String)"Not initialized.";
What's the point in *that*?
(All code above has been paraphrased. The syntax is preserved but
the semantics aren't. The real code is under NDA.)
--
/-- Joona Palaste ([email protected]) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"The large yellow ships hung in the sky in exactly the same way that bricks
don't."
- Douglas Adams