在我的项目中,我们将使用Java 7,maven-compiler-plugin并且我们假设在Maven编译之后,使用Java 8的所有代码都不应该成功编译.
但是,就我而言,有一个文件Arrays.stream(T[] array)可以在Java 8中使用,它仍然可以成功编译.下面是pom.xml配置Java版本的一些文件.请您查看并告诉我为什么我的文件仍可以成功编译,尽管我将其配置为Java 7?
对于pom.xml,我跳过依赖项等等,只列出属性和构建.
<properties>
<java.version>1.7</java.version>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven-compiler-plugin.version}</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
</plugins>
</build>
Run Code Online (Sandbox Code Playgroud)
对于我在Java 8中使用方法的文件,该行是这样的:
buffer.append(Arrays.stream(arg).collect(Collectors.joining("/")));
Run Code Online (Sandbox Code Playgroud)
我想要的是,因为我在Maven中配置Java版本为7并且在编译之后,使用Java 8的文件不应该成功编译并显示诸如"......仅允许在源级别1.8或更高级别的错误" ".