java - Arrays.asList("") returns List interface, how can object creation be possible in this case? -


this question has answer here:

i know object cannot created interface :

list list2 = new list();  // error. 

when work arrays.aslist(),i'm confused, because function returns list , following code works perfectly:

list list1 = arrays.aslist("a","b","c");  // works 

right side of equation returns list. code becomes list list1=new list(); how can possible , how code works although right side returns interface, didn't understand. can explain please? in advance

arrays.aslist(...) returns new arraylist.

due polymorphism can state returns list, , return implements list interface. arraylist is list, can returned.

extra note: arraylist aslist using created in arrays class anonymous class extends functionality of arraylist class create constructor accepts native array.


Comments

Popular posts from this blog

c# - How can I have the VS Debugger break in the correct location for exceptions thrown in Async methods in a Console App? -

php - Issues outputting data after prepared statement with loops -

javascript - How to pass a property by reference -