David Holmes wrote:
Joe Darcy said the following on 08/04/11 12:33:
David Holmes wrote:
Using wildcards makes the subtyping work along the type argument axis.

So what is the right fix here? To declare the underlying Vector as a Vector<?> and cast it to something concrete when needed? It seems very wrong to me to be inserting raw type casts all through this code.

It isn't entirely clear to be from a quick inspection of the code what the actual type usage is. A writable general Vector should be a Vector<Object> and Vector just meant for reading should be a Vector<?> (or the equivalent Vector<? extends Object>).

If the type usage is "a sequence of X's and Y's" where X and Y don't have some useful supertype, I would recommend using a somewhat different set of data structures, like a list of type-safe heterogeneous containers or a list of a new package-level XorY class.

Buried in one of Sasha's emails it says:

"The current code uses it to store Strings and Vector<String>s."

Hence it is declared Vector<Object>.

This is looking to me like code that should not have been generified.


Hmm. If String or Vector<String> are the two kinds of stored values, I would recommend Vector<Vector<String>> where a lone string was wrapped in a vector. (Actually, I would recommend a List<List<String>>, but that may be beyond the scope of this cleanup.

-Joe

Reply via email to