RFR: 8322810: Lambda expression types can't be classes [v6]
Maurizio Cimadamore
mcimadamore at openjdk.org
Thu Apr 10 21:13:38 UTC 2025
On Thu, 10 Apr 2025 18:37:12 GMT, Vicente Romero <vromero at openjdk.org> wrote:
>> Currently javac is accepting code like:
>>
>>
>> class Test {
>> void m() {
>> var r = (Test & Runnable) () -> System.out.println("Hello, World!");
>> }
>> }
>>
>>
>> according to: `4.9 Intersection Types` a notional interface can't be induced here as one of the components is a class different from `j.l.Object`
>>
>> With this fix this code pattern will be rejected with a compiler error
>>
>> TIA
>
> Vicente Romero has updated the pull request incrementally with one additional commit since the last revision:
>
> minor error in condition
test/langtools/tools/javac/lambda/ClassInIntersectionTypeTest.java line 32:
> 30: static Class<? extends Annotation> myAnnoType() { return null; }
> 31: @interface Anno {}
> 32: Anno a = (Anno & Serializable) ()-> null; // annotations not allowed
Actually, I wonder -- the annotation should not be allowed in any position right? Not just in the first type? E.g. since an annotation is an interface, you can also have:
`Runnable & Anno1 & Anno2`
Do we detect those?
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/24548#discussion_r2038343478
More information about the compiler-dev
mailing list