On 12/17/2011 10:20 AM, Knute Johnson wrote:
Which brings me back to my real question, can you
extend a generic class and still be generic?
Yes of course.
model.addElement("test");
^
required: E#1
found: String
reason: actual argument String cannot be converted to E#1 by method
invocation conversion
The problem is that you don't *have* a generic type. You have a
parametrized type of String. Otherwise, you can't stick a String in that
thing. Which is why the compiler is complaining.
Roedy's example compiles because it matches what you did. It
parametrizes the type to String because that's what you have.
No, you cannot have a "generic" class, then assume that you can also use
"string" as a type. Generics specifically prevent that.
You could put a bound on the type of E, like <E super String> and I
think that would work (I didn't test it). But since that is basically
String, CharSequence, or Object, it's really kinda limiting while being
baroque at the same time. I'd just use "String" or "CharSequence" or
"Object" unless you're really sure that the ability to parametrize that
type is really important.
Thanks for that and to John for giving me direction to follow.
parameters. You can extend a parameterized(?) generic class (eg.
limited to String types, which is what I really needed anyway.