java - Theory : List declaration Object list = new ArrayList(); -


i have exam coming i'm studying for.. , thinking of elegant way answer following question, current answer (based on information answer on stackoverflow)

the above initialization not possible, compile missing identifier in declaration, , other functions such add, remove not available.

the question..

consider following code snippet. possible assign instance of arraylist variable declared object done in line 1? explain.

  object strings = new arraylist();    strings.tostring(); 

what other ways answer this? , please provide wikipedia/resources, can research further how compiler translate bytecode? thank you

consider following code snippet. possible assign instance of arraylist variable declared object done in line 1? explain.

   object strings = new arraylist();     strings.tostring(); 

yes possible. object super type of arraylist (in fact, object super type of java reference types). legal declare variable of super type of actual type assigned.

a similar situation occurs when define list concrete implementation of arraylist:

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

Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -