为什么java 7不能使用diamond运算符和multi-catch语句 [英] Why can't java 7 use diamond operator and multi-catch statement
问题描述
private Map< String,List< InstrumentationClassData> ;> classMap = new HashMap<>(); // InstrumentingAgent中的第36行
InstrumentingAgent第63行中的多捕获块
} catch(InstrumentationException | JAXBException e){
e.getMessage();
}
我在编译时遇到以下错误。为什么不起作用?我究竟做错了什么。我正在使用IntelliJ IDE。
[错误]无法执行目标org.apache.maven.plugins:maven-compiler-插件:2.3.2:在项目检测代理上编译(default-compile):编译失败:编译失败:
[错误] / home / Documents / instrumentation-agent / src / main / java / org / wso2 / das / javaagent / instrumentation / InstrumentingAgent.java:[36,79]错误:-source 1.5
[ERROR]不支持菱形运算符(使用-source 7或更高版本启用钻石运算符)
[ ERROR] /home/Documents/instrumentation-agent/src/main/java/org/wso2/das/javaagent/instrumentation/InstrumentingAgent.java:[63,47]错误:-source 1.5 $不支持multi-catch语句b $ b [错误](使用-source 7或更高版本启用多捕获语句)
根据我读到的钻石操作员应该使用Java 7.但为什么我得到这个。如果我用相关类型填充钻石,那么IDE会将它们变成灰色并说它可能已经被钻石操作员取代。但是当我替换它时会出现以下错误。
在pom中添加以下内容解决了编译错误,
< plugin>
< artifactId> maven-compiler-plugin< / artifactId>
< version> 3.2< / version>
< configuration>
< source> 1.7< / source>
< target> 1.7< / target>
< / configuration>
< / plugin>
um using Java 7 (1.7.0_67) and Project language level is set to 7-Diamonds,ARM, multi-catch. My code is as follows, the lines that throw the compilation errors while building using maven.
private Map<String, List<InstrumentationClassData>> classMap = new HashMap<>(); //line 36 in InstrumentingAgent
Multi-catch block in InstrumentingAgent line 63
} catch (InstrumentationException | JAXBException e){
e.getMessage();
}
I am getting following errors when compiling. Why doesn't it work? What am I doing wrong. I am working on IntelliJ IDE.
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile (default-compile) on project instrumentation-agent: Compilation failure: Compilation failure:
[ERROR] /home/Documents/instrumentation-agent/src/main/java/org/wso2/das/javaagent/instrumentation/InstrumentingAgent.java:[36,79] error: diamond operator is not supported in -source 1.5
[ERROR] (use -source 7 or higher to enable diamond operator)
[ERROR] /home/Documents/instrumentation-agent/src/main/java/org/wso2/das/javaagent/instrumentation/InstrumentingAgent.java:[63,47] error: multi-catch statement is not supported in -source 1.5
[ERROR] (use -source 7 or higher to enable multi-catch statement)
According to what I read diamond operator should work with Java 7. But why am I getting this. If I fill the diamonds with relevant types then the IDE turn them gray and say it could have replaced with diamond operator. But when I replace it gives following errors.
Adding following to the pom solved the compilation error,
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.2</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
这篇关于为什么java 7不能使用diamond运算符和multi-catch语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!