简体   繁体   中英

java -Syntax error, parameterized types are only available if source level is 5.0

I am getting this compilation error on running a simple java program in unix from command line :

   ERROR in test.java (at line 92)
        List fileNames = new ArrayList<String>();
                                       ^^^^^^
   Syntax error, parameterized types are only available if source level is 5.0

This same question Java - Iterator: "Syntax error, parameterized types are only available if source level is 5.0" has answers that generics were introduced in java version > 5.0, but when I do java -version from command line it shows :

java version "1.6.0_24"
OpenJDK Runtime Environment (IcedTea6 1.11.6)

Compliance version is set to 1.4 by default :

Compliance options:
-1.3               use 1.3 compliance level (implicit -source 1.3
                   -target 1.1)
-1.4             + use 1.4 compliance level (implicit -source 1.3
                   -target 1.2)
-1.5               use 1.5 compliance level (implicit -source 1.5
                   -target 1.5)
-1.6               use 1.6 compliance level (implicit -source 1.6
                   -target 1.6)
-source <version>  set source level: 1.3 to 1.6 (or 5, 5.0, 6 or 6.0)
-target <version>  set classfile target level: 1.1 to 1.6 (or 5, 5.0, 6 or
                   6.0)

How can I change it to 1.5 from command line.

That is the Java Runtime Environment not the development kit.

Check the javac command's version.

Also if you are using an IDE make sure the proper Java version, JDK is being used.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM