"Overriding" instance variables in subtype: Possible risks?
Posted
by sebastiangeiger
on Stack Overflow
See other posts from Stack Overflow
or by sebastiangeiger
Published on 2010-05-19T10:23:23Z
Indexed on
2010/05/19
10:30 UTC
Read the original article
Hit count: 201
Say I had a class SuperClass and two subclasses SubClassA and SubClassB that inherit from SuperClass.
abstract class SuperClass{
...
List someList;
...
}
class SubClassA extends SuperClass{
...
List<String> someList;
...
}
class SubClassB extends SuperClass{
...
List<Integer> someList;
...
}
That way it is convenient because I can get someList.size()
in Superclass
and have Typesafety in the Subclasses.
The problem is that it does not "feel" right, can you think of potential hazards this apporach has that I am not aware of?
© Stack Overflow or respective owner