Akshay Naik :
As suggested almost everywhere shall I be using interface all the time, especially when working with collections.
// Using interfaces
List<Integer> list = new LinkedList<Integer>();
((LinkedList) list).offerFirst(num);
//Using concrete class
LinkedList list = new LinkedList<Integer>();
list.offerFirst(num);
In first approach compiler gives warning and even syntax seems cumbersome.
warning: [unchecked] unchecked call to offerFirst(E) as a member of the raw type LinkedList
Eran :
If you are using the offerFirst
method, perhaps you should be programming to the Deque
interface (which represents double ended queue) instead of the List
interface:
Deque<Integer> deque = new LinkedList<Integer>();
deque.offerFirst(num);