Skip to content

Assignability of raw and parameterized types for type variables with multiple bounds (CDI-440) #682

@ljnelson

Description

@ljnelson

I happened to notice that CDI-440 does not seem to have any resolution in the current version of the CDI specification.

Following the rules in the Jira issue, which read:

The CDI project is part ofJakarta and uses GitHub issues as it's issue tracking system.
Therefore, all issues in CDI JIRA project are being bulk-closed as described in this GitHub issue.
If you feel like this particular issue deserves ongoing discussion, investigation or fixes in CDI/CDI TCK, please create a new issue under GitHub repository and include a link to this JIRA.
For specification related question/issues, please use - https://github.com/eclipse-ee4j/cdi/issues
For CDI TCK related questions/issues, please use - https://github.com/eclipse-ee4j/cdi-tck/issues

…I am filing this issue to resurrect CDI-440.

The original issue reads:

Rules defined in section '5.2.4. [2.4.2.4] Assignability of raw and parameterized types' do not consider the case when a type variable has multiple bounds.

For example, the bullet

the required type parameter and the bean type parameter are both type variables and the upper bound of the required type parameter is assignable to the upper bound, if any, of the bean type parameter.

should have meaning similar to:

... for each upper bound T of the bean type parameter, there is an (at least one) upper bound of the required type which is assignable to T.

Consider the following example:

  • interfaces Bar, Baz, Foo
class BarImpl implements Bar { ... }
interface MyInterface<T> { ... }
  • bean:
class MyBean<T extends Bar & Baz & Foo> implements MyInterface<T> { ... }
  • injection point:
class TestClass<U extends BarImpl & Baz> {
@Inject
MyInterface<U> bean;
}

MyBean should not be assignable to this IP as U does not have the bound Foo. However, if e.g. BarImpl implemented also Foo, it should be OK, i.e. MyBean could be injected.

Please, correct me if I am wrong.

A comment indicates that this interpretation would seem to be correct, but it was never adopted.

There is a related issue that indicates that Weld adopted and implemented this unofficial interpretation.

The TCK appears to perhaps enforce this unofficial interpretation as well.

I'm not sure the suggested language is exactly correct, but the spirit of it seems correct.

Metadata

Metadata

Assignees

No one assigned

    Labels

    spec-clarificationAn issue requesting clarification in the specification

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions