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
Post a Comment