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