RFR: 8322810: Lambda expressions can implement classes [v4]

Maurizio Cimadamore mcimadamore at openjdk.org
Thu Apr 10 13:48:52 UTC 2025


On Wed, 9 Apr 2025 19:54:07 GMT, Vicente Romero <vromero at openjdk.org> wrote:

>> test/langtools/tools/javac/diags/examples/NotAnInterfaceComponent.java line 29:
>> 
>>> 27: 
>>> 28: class NotAnInterfaceComponent {
>>> 29:     Object o = (String & Runnable) ()-> { };
>> 
>> How was this rejected before? The generated compiler keys look strange...
>
> it was rejected because javac was trying to determine the function descriptor associated with the supposed functional interface that could be derived from the intersection of `String & Runnable` a this is impossible then it was failing. This check is at `DescriptorCache::findDescriptorInternal`. But if we have an empty class as in the test case that shows the bug that only inherits from `j.l.Object` but doesn't defines any other method, then javac was only seeing the method defined in the interface and thus a function descriptor was "found". See that the filter `DescriptorFilter` used by `DescriptorCache::findDescriptorInternal` all methods already defined in `j.l.Object`

I see - I did some debugging, and the issue with `String` is that there's more abstracts methods like `describeConstable` -- which then trigger a compilation error. I agree that it's better to validate the intersection type upfront.

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/24548#discussion_r2037454671


More information about the compiler-dev mailing list