You can define a default implementation for Kotlin I / F, but you need to set it in advance to use the default implementation from Java side. This time I will write down the setting method.
Add -Xjvm-default = compatibility
to the argument of the part that defines to compile kotlin in pom.xml
Example:
pom.xml
<plugin>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-plugin</artifactId>
<version>${kotlin.version}</version>
<executions>
<execution>
<id>compile</id>
<goals> <goal>compile</goal> </goals>
<configuration>
<sourceDirs>
<sourceDir>${project.basedir}/src/main/kotlin</sourceDir>
<sourceDir>${project.basedir}/src/main/java</sourceDir>
</sourceDirs>
<args>
<arg>-Xjvm-default=compatibility</arg>
</args>
</configuration>
</execution>
<execution>
<id>test-compile</id>
<goals> <goal>test-compile</goal> </goals>
<configuration>
<sourceDirs>
<sourceDir>${project.basedir}/src/test/kotlin</sourceDir>
<sourceDir>${project.basedir}/src/test/java</sourceDir>
</sourceDirs>
<args>
<arg>-Xjvm-default=compatibility</arg>
</args>
</configuration>
</execution>
</executions>
</plugin>
Describe jvmTarget in properties Example:
pom.xml
<properties>
<jdk.version>1.8</jdk.version>
<encoding>UTF-8</encoding>
<kotlin.version>1.3.60</kotlin.version>
<kotlin.compiler.jvmTarget>1.8</kotlin.compiler.jvmTarget>
</properties>
@JvmDefault
annotation to the method that you want Java to recognize as the default implementation.That is all.
Recommended Posts