aspose file tools*
The moose likes Beginning Java and the fly likes What is the difference between ArrayList and ArrayList<.....Any Class Here....>? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "What is the difference between ArrayList and ArrayList<.....Any Class Here....>?" Watch "What is the difference between ArrayList and ArrayList<.....Any Class Here....>?" New topic
Author

What is the difference between ArrayList and ArrayList<.....Any Class Here....>?

Vishal Kashyap
Ranch Hand

Joined: Aug 07, 2010
Posts: 73

Hi,
Right now; I am studying Head First Java, and little bit confused about----

ArrayList and ArrayList<.....Any Class Here....>

as I know, ArrayList always comes with their angle brackets; shows, which class it was for.
but getting confused, because of its(ArrayList) use without angle brackets and class in it. at page.287 first column(and several places).


I'd like to know,

could we use ArrayList like that i.e. without angle brackets & their class? if yes, then what does it mean to?

As I think, if we don't use angle brackets; then it means ArrayList will use Object class. Isn't it?

Please, guide me, here.
Thanks.


MCSA 2003 | Preparing For OCPJP/SCJP6
Stephan van Hulst
Bartender

Joined: Sep 20, 2010
Posts: 3615
    
  14

Any generic type (List, Set, Map, Class, Comparable, etc) that is not properly parameterized with angle brackets is known as a 'raw generic type'. The only reason they exist is because of backwards compatibility with older Java versions that did not have generics. Never use raw types.

Having said that, raw types function as if they were parameterized with Object. The difference is that you can assign any instance of a parameterized type to it:

Here is an example: ArrayList list = new ArrayList<Something>(). This stands in contrast with: ArrayList<Object> = new ArrayList<Something>(). This won't compile.

With raw types, the compiler won't do any checking for you, and you have to cast objects yourself. Don't use raw types. Ever.
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

See Generics for more information.


"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: What is the difference between ArrayList and ArrayList<.....Any Class Here....>?