JDK-8221373 : Missing checkcast in void-returning lambda
B. Blaser
bsrbnd at gmail.com
Wed May 1 13:42:56 UTC 2019
Hi,
I looked quickly at Liam's example, but I don't think JDK-8203338
introduced any regression in javac.
The target return type is 'void' and the unnecessary 'checkcast' is no
more emitted before a simple 'return'.
But trying the following example:
public abstract class Checkcast {
interface I<X> {
X d();
}
abstract <X> I<X> c();
interface R<X> {
X run();
}
void f() {
R<Void> r = () -> this.<Void>c().d();
r.run();
}
public static void main(String... args) {
new Checkcast() {
I<Long> c() {
return new I<Long>() {
public Long d() { System.out.println("OK"); return 0L; }
};
}
}.f();
}
}
the 'checkcast' is still emitted before 'areturn' along with an
unchecked warning and a CCE occurs as expected:
private java.lang.Void lambda$f$0();
Code:
0: aload_0
1: invokevirtual #7 // Method c:()LCheckcast$I;
4: invokeinterface #8, 1 // InterfaceMethod
Checkcast$I.d:()Ljava/lang/Object;
9: checkcast #9 // class java/lang/Void
12: areturn
Do we agree?
Thanks,
Bernard
More information about the compiler-dev
mailing list