Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why <> operator is not allowed for source below 1.7? [closed]

Tags:

java

in a java program , I have the following line of code :

HashMap<String, String> query_args = new HashMap<>();

and i receive the following error:

'<>' operator is not allowed for source level below 1.7

I tried to change the project compliance and jre to 1.7 but then eclipse could not resolve the imports. I am using jre 1.6.

Any suggestions?

like image 348
panipsilos Avatar asked Apr 05 '13 23:04

panipsilos


2 Answers

Prior to Java 7 (1.7 here), you needed to do

HashMap<String, String> query_args = new HashMap<String, String>();

Its referred to as the diamond operator, and is not backwards-compatible with earlier versions of Java.

like image 80
Jason Avatar answered Oct 02 '22 02:10

Jason


Because that wasn't introduced until Java 7. I really don't know how else to answer that question, besides chronicling the history of Java.

Regarding imports, you should research why Eclipse cannot resolve whichever imports they are when set to Java 1.7, and if needed post that as a separate question.

like image 42
djechlin Avatar answered Oct 02 '22 02:10

djechlin