Skip to content

Make the return type of Instance.handles() covariant#570

Merged
manovotn merged 1 commit intojakartaee:masterfrom
Ladicek:covariant-instance-handles
Dec 1, 2021
Merged

Make the return type of Instance.handles() covariant#570
manovotn merged 1 commit intojakartaee:masterfrom
Ladicek:covariant-instance-handles

Conversation

@Ladicek
Copy link
Copy Markdown
Member

@Ladicek Ladicek commented Dec 1, 2021

The Instance.handles() method returns an Iterable of contextual
reference handles (Instance.Handle<T>). It used to be defined in
an invariant way (Iterable<Handle<T>>), which prevents CDI Lite
implementations from exposing subtypes of Instance and
Instance.Handle as public API. This commit changes the return
type to covariant Iterable<? extends Handle<T>>. With that change,
CDI Lite implementations can expose a CustomInstance, which extends
Instance and overrides the Instance.handles() method. The method,
in turn, can return Iterable<CustomInstanceHandle<T>>, where
CustomInstanceHandle extends Instance.Handle.

The `Instance.handles()` method returns an `Iterable` of contextual
reference handles (`Instance.Handle<T>`). It used to be defined in
an invariant way (`Iterable<Handle<T>>`), which prevents CDI Lite
implementations from exposing subtypes of `Instance` and
`Instance.Handle` as public API. This commit changes the return
type to covariant `Iterable<? extends Handle<T>>`. With that change,
CDI Lite implementations can expose a `CustomInstance`, which extends
`Instance` and overrides the `Instance.handles()` method. The method,
in turn, can return `Iterable<CustomInstanceHandle<T>>`, where
`CustomInstanceHandle` extends `Instance.Handle`.
@manovotn manovotn merged commit 448da1f into jakartaee:master Dec 1, 2021
@Ladicek Ladicek deleted the covariant-instance-handles branch December 2, 2021 08:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants