java - Declaration difference between ArrayList and collection -


what's difference between following both ways

  1. collection<string> obj = new arraylist<string>();
  2. 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

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -