Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #10832
| From | markspace <-@.> |
|---|---|
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: Generics ? |
| Date | 2011-12-17 10:54 -0800 |
| Organization | A noiseless patient Spider |
| Message-ID | <jcioh3$k6d$1@dont-email.me> (permalink) |
| References | <jcem2m$gbm$1@dont-email.me> <ag5me7h7pph1d4n2b05uvgump03dp7ig0t@4ax.com> <jchb74$n8m$1@dont-email.me> <2eOdnXdWwdSD2HHTnZ2dnUVZ_t6dnZ2d@posted.palinacquisition> <jcimia$9dh$1@dont-email.me> |
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.
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Generics ? Knute Johnson <nospam@knutejohnson.com> - 2011-12-15 21:48 -0800
Re: Generics ? Peter Duniho <NpOeStPeAdM@NnOwSlPiAnMk.com> - 2011-12-15 22:03 -0800
Re: Generics ? Tassilo Horn <tassilo@member.fsf.org> - 2011-12-16 08:30 +0100
Re: Generics ? Peter Duniho <NpOeStPeAdM@NnOwSlPiAnMk.com> - 2011-12-16 00:08 -0800
Re: Generics ? Roedy Green <see_website@mindprod.com.invalid> - 2011-12-16 02:10 -0800
Re: Generics ? Knute Johnson <nospam@knutejohnson.com> - 2011-12-16 22:01 -0800
Re: Generics ? Peter Duniho <NpOeStPeAdM@NnOwSlPiAnMk.com> - 2011-12-16 23:30 -0800
Re: Generics ? Knute Johnson <nospam@knutejohnson.com> - 2011-12-17 10:20 -0800
Re: Generics ? markspace <-@.> - 2011-12-17 10:54 -0800
Re: Generics ? Knute Johnson <nospam@knutejohnson.com> - 2011-12-17 11:25 -0800
Re: Generics ? Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2011-12-17 21:20 -0800
Re: Generics ? "Qu0ll" <Qu0llSixFour@gmail.com> - 2011-12-18 21:08 +1100
Re: Generics ? Lew <lewbloch@gmail.com> - 2011-12-18 08:17 -0800
Re: Generics ? markspace <-@.> - 2011-12-18 08:43 -0800
Re: Generics ? Peter Duniho <NpOeStPeAdM@NnOwSlPiAnMk.com> - 2011-12-17 11:33 -0800
Re: Generics ? Knute Johnson <nospam@knutejohnson.com> - 2011-12-17 11:40 -0800
Re: Generics ? Peter Duniho <NpOeStPeAdM@NnOwSlPiAnMk.com> - 2011-12-17 11:47 -0800
Re: Generics ? Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-12-17 15:13 -0500
Re: Generics ? Roedy Green <see_website@mindprod.com.invalid> - 2011-12-17 02:46 -0800
Re: Generics ? "John B. Matthews" <nospam@nospam.invalid> - 2011-12-17 11:18 -0500
Re: Generics ? Knute Johnson <nospam@knutejohnson.com> - 2011-12-17 11:16 -0800
csiph-web