I would suggest you check the compiler compliance level is set to 1.5 or higher in your project.
You can do it like this:
Project->Properties->Java Compiler
If Enable project specific settings are not set, use the Configure Workspace Settings link to check the global compiler compliance level.
Looking for a Java tutorial? Check out the Java course from Intellipaat.