If your project has multiple modules, also check that every module uses language level 6 or above, or use the project's language level (see Project Settings > Modules > xxx > Language level).
You may need to reload your project once it is modified.
I ran into this problem for the first time while using a multi module maven project. As other answers / IDE suggested, we need to set the language level.
Rather than changing the setting of IDE, to make the project IDE agnostic, I update the parent pom with below properties, which solved the issue.