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

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -