在Intellij 14中将lambdas用于引发异常的接口时,Intellij会错误地突出显示它们为错误。
我一直在尝试以更简单的形式重现该错误,但这并不容易。我现在被迫用匿名内部类替换我的lambda。
好的,我能够在这里找出根本问题,并能够重现一个可行的示例:
// Works fine
public static void exampleOne() throws IOException {
methodOne();
methodTwo(() -> {
});
}
// Works fine
public static void exampleTwo() throws IOException {
// IOException bubbles up here, which is thrown by the method signature
methodTwo(() -> {
methodOne(); // throws IOException
});
}
// Works fine
public static void exampleThree() throws IOException {
methodTwo(() -> {
methodOne();
methodTwo(() -> {
});
});
}
// !!!!!! Error !!!!!!!!
public static void exampleFour() throws IOException {
methodTwo(() -> {
methodOne();
methodThree(() -> {
});
});
// Error here!
// It appears as if methodOne throws IOException, which should bubble up, and then methodThree call does not throw anything but Intellij gets confused
// If we look at exampleThree then we can see that a call to the same as the one we called first methodTwo does not yield any problems.
// This error does not exist in Intellij 13 and compiles fine with Java.
// Error type cannot be ignored in Intellij which is a major issue!
}
// Works fine
public static void exampleFourAnonymous() throws IOException {
methodTwo(new Callable<IOException>() {
@Override
public void call() throws IOException {
methodOne();
methodThree(() -> {
});
}
});
}
public static interface Callable<E extends Throwable> {
void call() throws E;
}
public static void methodOne() throws IOException {
}
public static <E extends Throwable> void methodTwo(Callable<E> lambda) throws E {
lambda.call();
}
public static <E extends Throwable> void methodThree(Callable<E> lambda) throws E {
lambda.call();
}
Intellij 13中不存在此错误。
这是有效的错误消息吗?
参考方案
现在已修复:youtrack.jetbrains.com/issue/IDEA-134808
IntelliJ Spring MVC教程部署 - java我尝试了tutorial,当我尝试部署webapp(IntelliJ 13.1.4 Ultimate)时,出现了一个奇怪的错误,如下面的屏幕快照所示。解决此错误的方法是什么? org.jdom.input.JDOMParseException: Error on line 742: The content of elements must consist o…
Intellij IDEA设置:无法解析符号println - javaIntellij给我这个错误的scala代码: Cannot resolve symbol "println" 项目设置:项目SDK: Intellij IDEA Community Edition IC-141.2735.5(openjdk version "1.8") 项目语言水平: 8 - Lambdas, ty…
java:继承 - java有哪些替代继承的方法? java大神给出的解决方案 有效的Java:偏重于继承而不是继承。 (这实际上也来自“四人帮”)。他提出的理由是,如果扩展类未明确设计为继承,则继承会引起很多不正常的副作用。例如,对super.someMethod()的任何调用都可以引导您通过未知代码的意外路径。取而代之的是,持有对本来应该扩展的类的引用,然后委托给它。这是与Eric…
如果陈述“不是陈述”? - java示例代码:public class SalCal { public static void main(String[] args) { int a=0; if (a > 1) String string = "fds";//hint:not a statement } } Intellij IDEA提示String string =…
Java:BigInteger,如何通过OutputStream编写它 - java我想将BigInteger写入文件。做这个的最好方式是什么。当然,我想从输入流中读取(使用程序,而不是人工)。我必须使用ObjectOutputStream还是有更好的方法?目的是使用尽可能少的字节。谢谢马丁 参考方案 Java序列化(ObjectOutputStream / ObjectInputStream)是将对象序列化为八位字节序列的一种通用方法。但…