Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!eternal-september.org!feeder.eternal-september.org!mx04.eternal-september.org!.POSTED!not-for-mail From: markspace <-@.> Newsgroups: comp.lang.java.programmer Subject: Re: Generics ? Date: Sat, 17 Dec 2011 10:54:24 -0800 Organization: A noiseless patient Spider Lines: 35 Message-ID: References: <2eOdnXdWwdSD2HHTnZ2dnUVZ_t6dnZ2d@posted.palinacquisition> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Sat, 17 Dec 2011 18:54:27 +0000 (UTC) Injection-Info: mx04.eternal-september.org; posting-host="XjIWM99mD7Ijfdu600oVPA"; logging-data="20685"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18f2aT3JaH8BsDGwKJ5UmUERl1whdLFn3Q=" User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:8.0) Gecko/20111105 Thunderbird/8.0 In-Reply-To: Cancel-Lock: sha1:ldgvU22kNJ8EAfcTMQ0F/xRGbvA= Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:10832 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 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.