List
is an interface and so can't instantiate it..You have to instantiate with its concrete implementations like ArrayList
.
Whether to use List
or ArrayList
totally depends on the context where it is being used..
If you want an ArrayList
you should instantiate it with an ArrayList though
Upcasting is usually performed for the purpose of reusability of a method and is usually done automatically..
Consider this method for sorting a list
public void sort(ArrayList lst);
You can only sort an ArrayList through this method.So if you want to sort LinkedList object you would have to create another method with LinkedList parameter
Now consider this method
public void sort(List lst);
You could now reuse this method by passing objects of the classes that implement List interface..So, you can now sort ArrayList
,LinkedList
,Stack
,Vector
using this same method..Thus you are now reusing this same method to sort different classes that implement List interface