Choose the correct result of compiling and running the following code:

import java.util.*;
class Generics13 {
  public static void main(String[] args) {
     List<Integer> list = new LinkedList<Integer>();
     list.add(1);
     list.add(4);
     list.add(-4);
     for(Iterator i = list.iterator(); i.hasNext();) {
            Integer in = i.next();
            System.out.println(in);
     }
  }
}
Explanation
Compliation will fail.
It is necessary to explicitly use type-cast: Integer in = (Integer) i.next();
or to declare type-patameter for Iterator: Iterator i = list.iterator();
The latter is better.

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback