I would be glad for feedback from (potential, as of the time of this writing) downvoters.
Let's assume I want to create a class storing a single object of class XXX and all its derived classes.
Should I go with LSP approach or with generics-with-bounded-type-parameter approach?
It seems to me that generic classes with a single bounded type parameters are not necessary, taking into account that Lieskov Substitution Principle (LSP) holds:
Both my below classes accept objects of the same types (only as an example I use class Object and its derived classes below).
class LSP { //this class uses Lieskov Substitution Principle (LSP)
Object a;
LSP(Object a) { this.a= a; }
Object get() { return this.a; }
}
class Gen<V extends Object> { //this is a generic class with bounded type parameter
V a;
Gen(V a) { this.a= a; }
V get() { return this.a; }
}
class Stackoverflow {
public static void main(String[] arg){
LSP l = new LSP(5);
Gen<Integer> g = new Gen<Integer>(5);
}
}
Can you point me to possible differences? Advantages? Pitfalls?