RFR: 8322810: Lambda expressions can implement classes [v4]
Vicente Romero
vromero at openjdk.org
Thu Apr 10 03:04:33 UTC 2025
On Thu, 10 Apr 2025 03:00:24 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:
>
> allow annotations as functional interfaces
strongly related to this change: javac is issuing an error implying that annotations can't be functional interfaces. But annotations inherit from `java.lang.annotation.Annotation` which is a rightful functional interface, I wonder if we should annotate it as such. So I have included a small change to allow for this. I can split it in a separate one but it will be weird allowing annotations in intersection types as lambda targets but not if used as an independent type
-------------
PR Comment: https://git.openjdk.org/jdk/pull/24548#issuecomment-2791426879
More information about the compiler-dev
mailing list