Possible bug with multiple generic bounds

Nir Lisker nlisker at gmail.com
Sat Jul 26 20:11:04 UTC 2025


Created https://bugs.openjdk.org/browse/JDK-8364144.

On Sat, Jul 19, 2025 at 7:28 PM Nir Lisker <nlisker at gmail.com> wrote:

> Hello,
>
> Initially reported in the Eclipse compiler since ECJ accepts code that
> javac does not:
> https://github.com/eclipse-jdt/eclipse.jdt.core/issues/4226. The current
> assessment is that the fault is with javac.
>
> Copying the example from there:
>
> ```
> interface Culprit {}
>
> class EntityInfo<E extends NumberGenerator<?> & Culprit> {}
>
> class NumberGenerator<N extends Number> implements NumberSupplier<N> {
>
> @Override
>     public N getNumber() {
>         return null;
>     }
> }
>
> interface NumberSupplier<N extends Number>  {
>
>     N getNumber();
> }
> ```
>
> javac fails with:
> ```
> error: getNumber() in NumberGenerator cannot implement getNumber() in
> NumberSupplier
> class EntityInfo<E extends NumberGenerator<?> & Culprit> {}
>                  ^
>   return type CAP#1 is not compatible with CAP#2
>   where N#1,N#2 are type-variables:
>     N#1 extends Number declared in class NumberGenerator
>     N#2 extends Number declared in interface NumberSupplier
>   where CAP#1,CAP#2 are fresh type-variables:
>     CAP#1 extends Number from capture of ?
>     CAP#2 extends Number from capture of ?
> 1 error
> ```
>
> Removing the Culprit bound:
> class EntityInfo<E extends NumberGenerator<?>> {}
>
> satisfies javac.
>
> Also noted that combining the supertypes explicitly is accepted:
> ```
> class X<T extends Number> extends NumberGenerator<T> implements Culprit {
> }
>
> class EI2<E extends X<?>> {}
> ```
>
> Thanks,
> Nir
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/compiler-dev/attachments/20250726/0096635e/attachment-0001.htm>


More information about the compiler-dev mailing list