Queue<String> myQueue= new LinkedList<String>();
myQueue.add("Joe");
System.out.println(myQueue);
// the above works fine
Queue<String> myQueue= new LinkedList<String>();
myQueue.addFirst("Joe");
System.out.println(myQueue);
// does not work because Queue Interface doesn't have addFirst
Queue<String> myQueue2= new PriorityQueue<String>();
myQueue2.add("joe");
myQueue2.add("tom");
myQueue2.add("ann");
System.out.println(myQueue2.remove());
// the above works - but because you are being implemented by PriorityQueue
// it will remove ann – works because PriorityQueue implements everything in Queue interface
ArrayList a = new ArrayList();
a.add("Joe");
System.out.println(a.get(0).length());
// will not compile because Objects don’t have lengths
ArrayList<String> a = new ArrayList();
a.add("Joe");
System.out.println(a.get(0).length());
// compiles and runs but with unsafe operations
ArrayList<String> a = new ArrayList<String>();
a.add("Joe");
System.out.println(a.get(0).length());
// compiles and runs fine
|