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条回答
Bombasti
2楼-- · 2020-02-07 17:24

Yes. Regardless of what anyone else says, Eclipse contains some bug(s) that sometimes causes the workspace setting (e.g. 1.6 compliant) to be ignored. This is even when the per-project settings are disabled, the workspace settings are correct (1.6), the JRE is correctly set, there is only a 1.6 JRE defined, etc., all the things that people generally recommend when questions about this issue are posted to various forums (as they often are).

We hit this irregularly, but often, and typically when there is some unrelated issue with build-time dependencies or other project issues. It seems to fall into the general category of "unable to get Eclipse to recognize reality" issues that I always attribute, rightly or wrongly, to refresh issues with Eclipse' extensive metadata. Eclipse metadata is a blessing and a curse; when all is working well, it makes the tool exceedingly powerful and fast. But when there are problems, the extensive caching makes straightening out the issues more difficult - sometimes much more difficult - than with other tools.

查看更多
淡お忘
3楼-- · 2020-02-07 17:29

It can be resolved as follows:

Go to Project properties.

Then 'Java Compiler' -> Check the box ('Enable project specific settings')

Change the compiler compliance level to '5.0' & click ok

Select the checkbox for "Use default compliance settings"

查看更多
ら.Afraid
4楼-- · 2020-02-07 17:30

Right click your project and choose properties in the properties dialog check the Java Compiler settings, maybe you have different workspace settings.

查看更多
欢心
5楼-- · 2020-02-07 17:34

This workaround is helpful when this problem pops up.

1) Set Workspace JRE to 1.5 (and apply/save). Projects will rebuild.

2)Set Workspace JRE back to 1.6 (and apply/save). Projects will rebuild.

All errors are then gone (for now at least).

查看更多
何必那么认真
6楼-- · 2020-02-07 17:34

I'm currently working with Eclipse Luna. And had the same problem. You might want to verify the compiler compliance settings, go to "Project/Properties/Java Compiler"

The Compiler compliance level was set to 1.4, I set mine to 1.5,(and I'm working with the JDK 1.8); it worked for me.

And if you had to change the setting; it might be useful to go to "Window/Preferences/Java/Compiler" And check to see that the Compiler compliance level is 1.5 or higher. Just in case you have a need to do another Java project.

查看更多
Evening l夕情丶
7楼-- · 2020-02-07 17:35

My guess would be that while you run eclipse itself with JDK 1.6, it's actually configured with a different default jre.

See Window->preferences->java->Installed JREs and make sure that the checked JRE is 1.6.

If the default JRE is indeed 1.6, chances are that it's a project specific setting. See that the project is configured to use the right JRE.

查看更多
登录 后发表回答