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?
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.
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"
Right click your project and choose properties in the properties dialog check the Java Compiler settings, maybe you have different workspace settings.
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).
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.
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 is1.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.