Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #10852

Re: Generics ?

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 Sun, 18 Dec 2011 08:43:33 -0800
Organization A noiseless patient Spider
Lines 31
Message-ID <jcl57n$3m2$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> <jcioh3$k6d$1@dont-email.me> <jciqaq$ujj$1@dont-email.me> <PKeHq.20143$c27.3382@newsfe22.iad> <yumdnduue4YXJnDTnZ2dnUVZ_g-dnZ2d@westnet.com.au>
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding 7bit
Injection-Date Sun, 18 Dec 2011 16:43:36 +0000 (UTC)
Injection-Info mx04.eternal-september.org; posting-host="XjIWM99mD7Ijfdu600oVPA"; logging-data="3778"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX186jcXfOVzjqfRvUpLb2GVyNyNocxveE2o="
User-Agent Mozilla/5.0 (Windows NT 6.1; WOW64; rv:8.0) Gecko/20111105 Thunderbird/8.0
In-Reply-To <yumdnduue4YXJnDTnZ2dnUVZ_g-dnZ2d@westnet.com.au>
Cancel-Lock sha1:LJQ9B5KKw+roHExlz+HEsUdzwOQ=
Xref x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:10852

Show key headers only | View raw


On 12/18/2011 2:08 AM, Qu0ll wrote:
> "Daniel Pitts" wrote in message news:PKeHq.20143$c27.3382@newsfe22.iad...
>
>> FWIW, you probably shouldn't be extending JList anyway. You should be
>> implementing ListModel and/or adding listeners to a JList. Pretty much
>> the only Swing "J*" class you ever really need to extend is JComponent.
>
> But what if you want a special type of JList or JPanel etc. that you can
> just drop in wherever a JComponent would be accepted in multiple places
> in your program or other programs? How can you avoid subclassing in
> those cases?


Well, the first thing you should do is to read the documentation 
*carefully* to make sure that what you want to do isn't implemented 
already.  Sometimes there's a helper class or method that instantiates 
common implementations for you, with out you having to do anything.

In the specific case of JPanel, it is not generic, and always accepts 
objects of type Component.  (There's that readin' documentation thing; I 
wasn't sure until I looked it up.)  There's no way to change that, as 
the Java rules of inheritance preclude it.

For JList, if you really just need a type of JComponent (or I'd 
recommend Component), then just make a JList<JComponent>.  You don't 
need to subclass to get that, you just parametrize the type.  That's why 
generics are an improvement, they don't require sub-classing.

Don't overlook <?> (unknown type) or just parametrize with type of 
Object, when appropriate.

Back to comp.lang.java.programmer | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


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