Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.help > #847
| Date | 2011-07-12 02:02 +0200 |
|---|---|
| From | Mayeul <mayeul.marguet@free.fr> |
| Newsgroups | comp.lang.java.help |
| Subject | Re: Instantiation of a class |
| References | <d98a873f-d5db-4243-be26-2109c25744b2@q12g2000prb.googlegroups.com> |
| Message-ID | <4e1b8dd1$0$32117$426a74cc@news.free.fr> (permalink) |
| Organization | Guest of ProXad - France |
On 12/07/2011 01:03, Fred wrote:
> Hello,
>
> I'm thinking about statements like String foo = new String("foo");
> When is the constructor specified not the name of the type of
> reference variable?
A common example is with collections:
List<String> notes = new ArrayList<String>();
Here I instanciated an ArrayList, but the rest of my code does not care
what kind of List it is operating on. If I later choose to make it a
LinkedList, a Collection.unmodifiableList() or an Array.asList(), I can.
But I cannot trimToSize(), though, so, if I need to, that mean I will
actually have to declare it an ArrayList and not a general List.
--
Mayeul
Back to comp.lang.java.help | Previous | Next — Previous in thread | Next in thread | Find similar
Instantiation of a class Fred <albert.xtheunknown0@gmail.com> - 2011-07-11 16:03 -0700
Re: Instantiation of a class lewbloch <lewbloch@gmail.com> - 2011-07-11 16:41 -0700
Re: Instantiation of a class lewbloch <lewbloch@gmail.com> - 2011-07-11 16:54 -0700
Re: Instantiation of a class Mayeul <mayeul.marguet@free.fr> - 2011-07-12 02:02 +0200
Re: Instantiation of a class Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-07-11 21:57 -0400
Re: Instantiation of a class Patricia Shanahan <pats@acm.org> - 2011-07-11 19:02 -0700
Re: Instantiation of a class Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-07-11 22:10 -0400
Re: Instantiation of a class Fred <albert.xtheunknown0@gmail.com> - 2011-07-11 20:29 -0700
Re: Instantiation of a class lewbloch <lewbloch@gmail.com> - 2011-07-12 14:35 -0700
Re: Instantiation of a class Gene Wirchenko <genew@ocis.net> - 2011-07-11 21:25 -0700
Re: Instantiation of a class Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-07-12 07:47 -0400
Re: Instantiation of a class lewbloch <lewbloch@gmail.com> - 2011-07-12 11:09 -0700
csiph-web