J2SE5.0 collection syntax

P

Peter Parker

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.
 
N

NeoGeoSNK

Peter said:
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.

Just use
type a = list.get();
 
S

Stefan Ram

Peter Parker said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top