java - Declaration difference between ArrayList and collection -
this question has answer here:
what's difference between following both ways
collection<string> obj = new arraylist<string>();
arraylist <string> obj = new arraylist<string>();
simple: in first case "forget" created arraylist - "remember" obj
has properties of implements collection interface.
and should rather going for:
list<whatever> items = new arraylist<>();
- yes, typically want "forget" kind of specific list class created - want remember list
- you want never use raw types (meaning: never omit generic type parameter) when dealing collections of any kind
Comments
Post a Comment