Unfortunately, I had to use the following signatures in the end:
```
<K1, V1> KStream<K1, V1> transform(final TransformerSupplier<? super K, ? super
V, KeyValue<K1, V1>> transformerSupplier,
final String... stateStoreNames);
<K1, V1> KStream<K1, V1> flatTransform(final TransformerSupplier<? super K, ?
super V, Iterable<KeyValue<K1, V1>>> transformerSupplier,
final String... stateStoreNames);
```
The reason is that I got similar compile errors as before with the following
signature for `flatTransform`:
```
<K1, V1> KStream<K1, V1> flatTransform(final TransformerSupplier<? super K, ?
super V, ? extends Iterable<? extends KeyValue<K1, V1>>> transformerSupplier,
final String... stateStoreNames);
```
I tried a couple of alternatives, but the only one that allowed me to define a
`TransformerSupplier` with an anonymous class and a lambda expression was the
one without any wildcards in the generics for the output of the operator. To be
consistent between `transform` and `flatTransform`, I also removed the
wildcards in the generics for the output of `transform`. Now, `transform` has
again the same signature as on the current trunk.
Lessons learned:
- Lambdas and anonymous classes have different representations in Java byte
code. See [this answer](https://stackoverflow.com/a/52447112/6822244) to my
stackoverflow question. I guess this is the reason for the differences in type
variable inference.
- There would be ways to define a lambda for the more flexible signatures for
`transform` and `flatTransform`, but they consists of casts and obscure
generics declarations in the lambda (see [my stackoverflow
question](https://stackoverflow.com/questions/52445222/using-lambda-impedes-inference-of-type-variable)).
Additionally, it is a trial and error process to get the lambda right. Thus,
something you do not want to expose to your user to.
- In Java 8, there exists [the `java.util.function.Supplier` functional
interface](https://docs.oracle.com/javase/8/docs/api/java/util/function/Supplier.html)
which is really similar to Kafka's `TransformerSupplier`. With the
`java.util.function.Supplier` the more flexible signatures for `transform` and
`flatTransform` seem to compile with lambdas (I have not thoroughly tested it,
though). The drawback here is that defining the transformer supplier by means
of an anonymous class does not seem to work anymore with the more flexible
signature (also here, I have not invested too much time to try it out).
[ Full content available at: https://github.com/apache/kafka/pull/5273 ]
This message was relayed via gitbox.apache.org for [email protected]