Hey, I have this Converter in Kotlin: ```class Ex...
# announcements
b
Hey, I have this Converter in Kotlin:
Copy code
class ExampleConverter<T> : Converter<T, String> {
    override fun convert(source: T): String? {
        TODO("Not yet implemented")
    }
}
it implements this Java interface:
Copy code
@FunctionalInterface
public interface Converter<S, T> {

	/**
	 * Convert the source object of type {@code S} to target type {@code T}.
	 * @param source the source object to convert, which must be an instance of {@code S} (never {@code null})
	 * @return the converted object, which must be an instance of {@code T} (potentially {@code null})
	 * @throws IllegalArgumentException if the source cannot be converted to the desired target type
	 */
	@Nullable
	T convert(S source);

}
The IDE says, that everything is fine. However when I try to compile I get:
Copy code
Class 'ExampleConverter' is not abstract and does not implement abstract member public abstract fun convert(p0: T!!): String?
'convert' overrides nothing
Any idea?
p
Try override fun convert(source: T*?*): String?
b
Still doesn’t compile. And the IDE is now also complaining:
p
Strange. I can't reproduce the issue. Possibly your module has some issues with java or kotlin version. Try to add this in build.gradle of your module:
Copy code
android {
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    kotlinOptions {
        jvmTarget = '1.8'
    }
}
b
My kotlinOptions look like this:
Copy code
kotlinOptions {
                freeCompilerArgs = listOf(
                    "-progressive",
                    "-Xinline-classes",
                    "-Xjsr305=strict",
                    "-Xjvm-default=enable",
                    "-Xopt-in=kotlin.ExperimentalUnsignedTypes"
                )
                jvmTarget = "11"
                javaParameters = true
            }
Java Toolchain is set to 11:
Copy code
java {
    toolchain {
        languageVersion.set(JavaLanguageVersion.of(11))
    }
}
p
Looks like this is the problem:
Copy code
"-Xjsr305=strict",
Try to remove it or set to "warn"
And BTW, why should you use the java interface? Can you just create the same interface in Kotlin? It's very simple interface.
b
the interface comes from Spring
p
I see, ok
j
look like your are using
Copy code
org.springframework.core.convert.Converter
which is come from spring
b
The thing with JSR 305 is: It is kinda a default. This compiler Arg is present in every new IDE project. I wonder why this should cause such problems now. I also tried to remove the other compilerArgs. The project does compile without
progressive
It fails to compile with Kotlin 1.4.20. Kotlin 1.4.10 works https://github.com/bjoernmayer/progressive-kotlin-issue
removing
progressive
or
Xjsr305=strict
compiler args leads to succesful compilation. However: both shouldn’t cause this IMO