pjfanning opened a new issue, #3712:
URL: https://github.com/apache/pekko/issues/3712

   Java generics are invariant, so several Java DSL parameters reject values 
that a Java user would reasonably expect to pass, typically a variable whose 
declared type is a narrower generic (e.g. `List<Source<T, NotUsed>>` or 
`List<ItemAdded>`). Lambdas mostly adapt to the target type; pre-typed 
variables, fields and method references do not.
   
   Adding wildcard bounds only changes the generic signature, not the erased 
descriptor, so this should be binary compatible (MiMa clean) and source 
compatible for existing Java and Scala callers.
   
   ### Parameters that reject ordinary Java variables
   
   | Location | Today | Suggested |
   |---|---|---|
   | `javadsl.Source.combine` `rest` | `java.util.List[Source[T, ? <: Any]]` | 
`java.util.List[? <: Graph[SourceShape[T], ?]]` |
   | `javadsl.Source.zipN`, `zipWithN` | `java.util.List[Source[T, ? <: Any]]` 
| `java.util.List[? <: Graph[SourceShape[T], ?]]` |
   | `javadsl.Source.mergePrioritizedN` | `java.util.List[Pair[Source[T, ? <: 
Any], Integer]]` | `java.util.List[? <: Pair[? <: Graph[SourceShape[T], ?], 
Integer]]` |
   | `javadsl.Sink.combine` `rest` | `java.util.List[Sink[U, ?]]` | 
`java.util.List[? <: Graph[SinkShape[U], ?]]` |
   | persistence-typed `javadsl.Effect.persist(events)` | 
`java.util.List[Event]` | `java.util.List[? <: Event]` |
   
   For example, `List<Source<Integer, NotUsed>> sources = ...; 
Source.zipN(sources)` does not compile today, and neither does passing a 
`List<ItemAdded>` to `Effect().persist(...)` when the behavior's event type is 
`Event`. The newer list-based `Source.combine` / `Sink.combine` overloads and 
`mergeAll` already use `java.util.List[? <: Graph[...]]`, and the scaladsl 
`persist` takes a covariant `immutable.Seq[Event]`.
   
   ### Inconsistencies with sibling operators
   
   The same operator has a bound in one class but not in its siblings:
   
   - `mapConcat`: `Source`, `SourceWithContext` and `FlowWithContext` use 
`Function[Out, ? <: java.lang.Iterable[T]]`; `Flow`, `SubFlow` and `SubSource` 
take a plain `java.lang.Iterable[T]`.
   - `statefulMapConcat`: the inner function returns a plain 
`java.lang.Iterable[T]` in `Source`, `Flow`, `SubFlow` and `SubSource`; should 
be `? <: java.lang.Iterable[T]`.
   - `recoverWith` / `recoverWithRetries`: `Source` and `Flow` 
`recoverWith(pf)` use `? <: Graph[SourceShape[Out], NotUsed]`; `SubFlow`, 
`SubSource` and `Flow.recoverWithRetries` do not.
   - `fanInStrategy` / `fanOutStrategy`: `Source.combine(first, second, rest, 
...)` uses `Function[Integer, ? <: Graph[...]]`; the list-based 
`Source.combine` overload and `Sink.combine` / `Sink.combineMat` do not.
   
   ### Tests
   
   Java tests should pass a variable of the narrower type (which fails to 
compile before the change), and `mimaReportBinaryIssues` for `stream` and 
`persistence-typed` should stay clean.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to