Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #10835
| Path | csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!news.glorb.com!border3.nntp.dca.giganews.com!Xl.tags.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local2.nntp.dca.giganews.com!nntp.posted.palinacquisition!news.posted.palinacquisition.POSTED!not-for-mail |
|---|---|
| NNTP-Posting-Date | Sat, 17 Dec 2011 13:33:50 -0600 |
| Date | Sat, 17 Dec 2011 11:33:50 -0800 |
| From | Peter Duniho <NpOeStPeAdM@NnOwSlPiAnMk.com> |
| User-Agent | Mozilla/5.0 (Macintosh; Intel Mac OS X 10.5; rv:8.0) Gecko/20111105 Thunderbird/8.0 |
| MIME-Version | 1.0 |
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: Generics ? |
| 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> |
| In-Reply-To | <jcimia$9dh$1@dont-email.me> |
| Content-Type | text/plain; charset=UTF-8; format=flowed |
| Content-Transfer-Encoding | 8bit |
| Message-ID | <_5Sdnag2-IwDc3HTnZ2dnUVZ_qqdnZ2d@posted.palinacquisition> (permalink) |
| Lines | 44 |
| X-Usenet-Provider | http://www.giganews.com |
| NNTP-Posting-Host | 50.46.118.188 |
| X-Trace | sv3-G6071Go/kOXcTMhxmS2eSTf2Zud344V76awRWtEvbsM/H/GEsdmVtn/7GvIwoJgy/n8EtU6rh/a5FXm!6T2fjFcy3urI8Ku3F/2euGjmHeaJYuNjNCRHWWuVHbr6pVKYSxJgTnbAsV1Fpibe8xxl9hdu0xTy!yGsjyn/QqjfdACkLnTJGJ8a+ZgNk/JECYHnnzfr0jjA= |
| X-Complaints-To | abuse@iinet.com |
| X-DMCA-Complaints-To | abuse@iinet.com |
| X-Abuse-and-DMCA-Info | Please be sure to forward a copy of ALL headers |
| X-Abuse-and-DMCA-Info | Otherwise we will be unable to process your complaint properly |
| X-Postfilter | 1.3.40 |
| X-Original-Bytes | 3368 |
| Xref | x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:10835 |
Show key headers only | View raw
On 12/17/11 10:20 AM, Knute Johnson wrote: > [...] > Example #4 Roedy's first suggestion compiles without warning but it is > no longer generic. Which brings me back to my real question, can you > extend a generic class and still be generic? As "markspace" says: of course you can. But you have to do it correctly. (It also helps if you don't keep your code examples secret, such as having a statement that calls "model.addElement()" that is important to you, but which you don't actually share with the rest of us). None of your examples actually followed the examples I provided precisely. In each case, you made a mistake: • example #1: you tried to declare a class name as if it had a generic type parameter, but used "String" as if it were the name of the parameter. • example #2: the declaration of the class is fine, but then in your code you made the illegal assumption that the type parameter "E" is actually "String", by trying to pass an instance of String to the addElement() method. • example #3: you failed to specify "String" as the type parameter for the base class, meaning you're extending it without generic support, hence the "unchecked" warning. • example #4: you can't make a class generic, but at the same time fix the type parameter as something specific. Frankly, I think example #4 is the most likely to be what you want. You appear to want to explicitly pass a string literal to the supporting types within your own derived class. If that's the case, then you have made the choice of the type parameter already. It _has_ to be String. If you actually want to declare a generic type yourself (e.g. so that you can reuse it generically), then you are not permitted to make any assumptions about the type parameter's value. That includes not passing string literals to a generic member, such as your example of the call to addElement(). Pete
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