Problem with Type mismatch for generic type extending another generic type


for context, I’m trying to write a Apache Beam job that writes to Kafka using Kotlin. The KafkaIO package has some example code I’m trying to convert to Kotlin (under Reading Kafka Topics.

This works fine, until the last line, in Java being:


writing this in Kotlin as


gives me a type mismatch error.

Error:(24, 13) Kotlin: Type mismatch: inferred type is Values<String!>! but PTransform<in PCollection<KafkaRecord<Long!, String!>!>!, PCollection<String!>!>! was expected

But Values<String!>! should be a subclass of PTransform. Here’s its Javadoc:

I don’t understand why this works in Java, but not in Kotlin. What with it being a million generics deep type, there’s probably an issue there, but type stuff has always been my weak point. Any help would be appreciated.


The issue has been resolved. One of the optional methods in the example creates a PCollection instead of a collection of KafkaRecords. That fixed it. Reading helps

1 Like