Re: why people use "Map m= new HashMap()" or "List l = new ArrayList()"?



Knute Johnson wrote On 10/20/07 04:37,:
Lew wrote:

Knute Johnson wrote:

It doesn't make a lot of sense to me. Generics were added to closely
control the type of parameters passed to a class that we then want to
make less type specific? It makes no sense to turn a LinkedList for
example into a plain List as you lose all of what makes it a
LinkedList. Of course you could assign it to a Deque.

Well, duhy, if you need the specific type you use the specific type. No
one is saying to be stupid about it.



The only two classes extended from List that you would ever want to do
this with are ArrayList and Vector.

The documentation describes ten core classes that
implement List, of which eight are concrete classes.

Since everyone hates Vector,
explain to me in what actual case this would be of any benefit and not
just confusing.

Do you think your program is in its final form when
you have finished debugging it? Nobody, not even you,
will ever want to modify it? Nobody, not even you, will
ever want to change his mind about an implementation
choice? "Hmm: Profiling tells me that a lot of time is
spent expanding and re-expanding and re-re-expanding this
ArrayList. We don't seem to need random access; maybe
LinkedList would be better." This sort of thing never
happens to you?

If not, all I can say is that you are more gifted at
predicting the future than I am. Given my temporally
foreshortened foresight, I prefer to leave myself as many
chances to change my mind as I possibly can. YMMV.

... but when Java 9 brings us SuperList ("faster than
a speeding bullet"), I bet I'll have an easier time adapting
my code to use it than you will with yours.

--
Eric.Sosman@xxxxxxx
.



Relevant Pages

  • Re: slurp slurp slurp .." Can Luke keep up with Tiger ...............
    ... When he's playing his best, nobody can beat him. ... he has enough control over his mind that he doesn't make bad ...
    (rec.sport.golf)
  • Re: A bit of clarification
    ... I looked at a Hackensack hack licence app. ... Nobody volunteered. ... Which is why you brag about not paying income tax and getting paid ... Make up your mind here. ...
    (misc.transport.road)
  • Re: believability
    ... necessary to install a confrontational bypass against that circuitry. ... nobody fucking reads it they just keep walking. ... a neutral mind that has been brainwashed and a brainwashed mind ...
    (misc.writing)
  • Re: Why are you all wasting your time?
    ... I lash out at nobody that doesn't merit it. ... I mind my own business. ... has had many masters who have all been poor masters, ... I'm speaking from a purely selfish, "win the game" POV that Civ4 ...
    (rec.games.frp.dnd)
  • Re: Why are you all wasting your time?
    ... I lash out at nobody that doesn't merit it. ... I mind my own business. ... has had many masters who have all been poor masters, ... If he simply played Civ4 long enough to master it he would well understand why it is sometimes in one's own best interests to help out one's enemies. ...
    (rec.games.frp.dnd)