Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / October 2006

Tip: Looking for answers? Try searching our database.

J2SE5.0 collection syntax

Thread view: 
Peter Parker - 13 Oct 2006 02:17 GMT
I am aware that the correct syntax for creating new collection is as
follows:

ArrayList<type>  list = new ArrayList<type>();

Could someone show me the correct syntax (if any) if one gets the collection
from a known casted object as below. ie., where should I put <type> on the
right side?

ArrayList<type> list = ((SomeClass)someClassObject).getSomeCollection();

Thanks much.
NeoGeoSNK - 13 Oct 2006 02:25 GMT
> I am aware that the correct syntax for creating new collection is as
> follows:
[quoted text clipped - 8 lines]
>
> Thanks much.

Just use
type a = list.get();
Stefan Ram - 13 Oct 2006 02:37 GMT
>I am aware that the correct syntax for creating new collection
>is as follows:
>ArrayList<type>  list = new ArrayList<type>();

 This is an expression statement. There is not a unique
 "correct syntax for creating new collection [objects]", while
 usually an invocation of a factory method or an instance
 creation expression ist involved.

>Could someone show me the correct syntax (if any) if one gets
>the collection from a known casted object as below. ie., where
>should I put <type> on the right side?
>ArrayList<type> list = ((SomeClass)someClassObject).getSomeCollection();

 There is no need to do so, though it might be possible in some
 cases. This depends on how »getSomeCollection« is declared
 (see its documentation). If it takes a type argument at all,
 it would look like:

object.<type>method();

 This does not necessarily have to be the same type as in
 »ArraysList<type>«. And this is not »collection syntax«, but
 method invocation syntax.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.