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