Eclipse: Syntax Error, parameterized types are onl

2020-02-07 17:10发布

I try to use the following code:

ArrayList<String>
Map<String, String>

Eclipse complains about both of them: Syntax Error, parameterized types are only if source level is 1.5.

I use JDK 1.6, but even if I go to compiler and switch the compliance to 1.5. It still give me this error. Any Idea why?

标签: java eclipse
17条回答
干净又极端
2楼-- · 2020-02-07 17:35

Go to Project properties.

Then 'Java Compiler' -> Check the box and "Enable project specific settings"

Uncheck the box to "Use Compliance from execution environment 'OSGi/Minimum-1.2' on the Java"

Then change the compiler compliance level to '1.5' and click Ok.

Rebuild it and your problem will be resolved.

查看更多
▲ chillily
3楼-- · 2020-02-07 17:37

I get this fairly regularily. Currently what's working for me (with Photon) is:

  • Close project
  • Open project

If this doesn't work :

  • Close project
  • Exit Eclipse
  • Restart Eclipse
  • Open Project

I know, stupid isn't it.

查看更多
甜甜的少女心
4楼-- · 2020-02-07 17:39

Single answer couldn't solve my problem so I used both :

  • First right click on the error in problems tab
  • click Quick fix
  • ok
  • right click on the project
  • build path
  • configure build path
  • remove JRE library
  • add JRE library

.... tada...done... :)

查看更多
迷人小祖宗
5楼-- · 2020-02-07 17:40

change the compiler version to lower value and do apply the changes. The compilation will fail.

Now update the version to required and do apply the changes, the workspace will get rebuild and the issue will get resolved.

查看更多
淡お忘
6楼-- · 2020-02-07 17:43

This works for me .

In eclipse go to project properties -> java compiler.

Then change to java higher than 1.5 .

change Compiler compliance settings to 1.6 change Generated.class files compatibility to 1.6 change Source compatibility to 1.6

Thanks. Screen Shot for changes

查看更多
贼婆χ
7楼-- · 2020-02-07 17:43

I was able to solve this in Eclipse Helios by right-clicking on the project, picking "Java Build Path", "Add Library...", "JRE System Library", "Workspace default JRE (jdk1.6.0_17)" and finally "Finish".

查看更多
登录 后发表回答