I have a Spring Boot project where I am introducing Kotlin alongside the Java. I have a Kotlin class ClassA.kt
that implements a Java interface from a library, JavaInterfaceA.java
. Then in the Java code of my project, I try to create a ClassA object and use it as a JavaInterfaceA, but it gives an error that: error: incompatible types: ClassA cannot be converted to JavaInterfaceA.
It seems like it isn’t recognizing the implementation of the interface. Any suggests on why this would be?
Specifics with the actual class types I’m using:
// Interface from library
public interface ItemProcessor<I, O> {
O process(I var1) throws Exception;
}
// In my Kotlin project code
class ProcessorA : ItemProcessor<Map<String, Object>, ContentItem> {
override fun process(params: Map<String, Object>): ContentItem {
...
return contentItem
}
}
// In my Java project code
public class ProcessorFactory {
public static ItemProcessor<Map<String, Object>, ContentItem> getContentItemProcessor(String processorId) {
...
return new ProcessorA(); // ERROR: ProcessorA cannot be converted to ItemProcessor<Map<String, Object>, ContentItem>
...
}
}