javaintellij-ideadiamond-operator

Error:(67, 51) java: diamond operator is not supported in -source 1.6 (use -source 7 or higher to enable diamond operator)


I want to use this library, I cloned it and imported it into IntelliJ IDEA 14.0.3, with JDK 1.8.0_77, but when I want to run the main method I get this error:

Error:(422, 50) java: diamond operator is not supported in -source 1.6
  (use -source 7 or higher to enable diamond operator)

what is going on here? how can I resolve it?


Solution

  • You are using a collection with the new (in Java 7) diamond operator,

    List<Integer> al = new ArrayList<>(); // <-- the diamond operator.
    

    In earlier versions of Java, you must specify the generic on the right hand side like

    List<Integer> al = new ArrayList<Integer>(); // <-- No diamond operator.
    

    or you could modify your IDE preferences to target Java 7+.