Skip to content

Commit

Permalink
Make the return type of Instance.handles() covariant
Browse files Browse the repository at this point in the history
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`.
  • Loading branch information
Ladicek authored and manovotn committed Dec 1, 2021
1 parent 50cde7a commit 448da1f
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions api/src/main/java/jakarta/enterprise/inject/Instance.java
Original file line number Diff line number Diff line change
Expand Up @@ -252,14 +252,14 @@ default boolean isResolvable() {
*
* @return a new iterable
*/
Iterable<Handle<T>> handles();
Iterable<? extends Handle<T>> handles();

/**
* Returns stream of {@link Handle} objects.
*
* @return a new stream of contextual reference handles
*/
default Stream<Handle<T>> handlesStream() {
default Stream<? extends Handle<T>> handlesStream() {
return StreamSupport.stream(handles().spliterator(), false);
}

Expand Down

0 comments on commit 448da1f

Please sign in to comment.