I just fixed it as follows:
Right click the project -> Open Module Settings -> Modules -> Sources -> 8 or higher
And then
If still encounter the error and using maven, you have to add the build configuration in your pom.xml:
org.apache.maven.plugins
maven-compiler-plugin
1.8
1.8