Why are the types different in Java variable declarations? -


this question has answer here:

what purpose of specifying different types on left , right side in java variable declarations?

for example, code standard:

list<string> l = new arraylist<>(); 

why don't:

arraylist<string> l = new arraylist<>(); 

or

object l = new arraylist<>(); // silly example shows 2 extremes 

  • this list<string> l = new arraylist<>(); allows instantiate types of list, arraylist or linkedlistof string. can use methods of list
  • arraylist<string> l = new arraylist<>(); can instantiate arraylist of string.
  • object l = new arraylist<>(); cannot use list methods.

Popular posts from this blog

javascript - Js, document.getElementById("ID").innerHTML, error -

objective c - Is there a way in OCMockito to make stubs fail when an unknown method is called? -

jquery - jqGrid update specific column data with out refreshing the entire column? -