Usage of Kotlin together with other languages, most notably Java. e.g. Calling Kotlin functions from Java, or using Java classes from Kotlin.
Questions tagged [kotlin-interop]
117 questions
3
votes
1 answer
Kotlin constructor delegation to inner data class?
We have an abstract Java class (which we can't modify) called AbstractClass that we want to implement in Kotlin. A requirement is the Kotlin implementation is serializable/deserializable to JSON using vanilla Jackson Databind. This has lead us to…

Johan
- 37,479
- 32
- 149
- 237
3
votes
1 answer
Parsing JSON with Kotlin JS 'fun parse(text: String): T`?
How can I use
fun parse(text: String): T
to parse JSON in Kotlin JS?
e.g. how can I parse this JSON string?
{
"couchdb": "Welcome",
"version": "2.0.0",
"vendor": {
"name": "The Apache Software Foundation"
}
}

ycomp
- 8,316
- 19
- 57
- 95
2
votes
1 answer
Kotlin to Java interoperability in hierarchial interfaces
I have two modules defines like this:
interface Module {
val parameter: JSONObject
}
abstract class FirstModule: Module {
abstract val message: Message
}
....
// many more Modules
I created a base listener interface for Module and another…

Sandeep Gupta
- 33
- 6
2
votes
1 answer
How to adjust Swift classnames for Kotlin Multiplatform project with Cocoapods?
In my Kotlin multiplatform project i heavily use namespaces. Also since i'm using MVP i have similar classnames.…

4ntoine
- 19,816
- 21
- 96
- 220
2
votes
3 answers
Kotlin (Mutable)List
If you access a Java value of type List<[Some Type]> in Kotlin, you will get the type (Mutable)List<[Some Type]!>!.
e.g.:
Java code:
public class Example {
public static List getList() {
return Arrays.asList("A", "B", "C");
…

Josef Zoller
- 921
- 2
- 8
- 24
2
votes
1 answer
Kotlin lambda / Java SAM interop - type mismatch
I have an existing Java interface defined as follows
public interface MyRetriever extends Function> {}
and want to define a variable holding a Kotlin lambda which conforms to the SAM conversion as per my understanding
var a…

Xipo
- 1,765
- 1
- 16
- 23
2
votes
1 answer
How to handle nullable generics with Java interop
I have a Java class that is out of my control, defined as:
public @interface ValueSource {
String[] strings() default {}
}
I am trying to use this class from a Kotlin file I control, like so:
class Thing {
@ValueSource(string = ["non-null",…

MariusVolkhart
- 449
- 1
- 4
- 12
2
votes
1 answer
Make proxy on Kotlin class from a Java library using ASM
I have a Java library that creates a proxy using ASM.
At one point, user sends a Kotlin class to it. I can detect it is a Kotlin class from Java, but I don't know how can I make a proxy from it? Everything what I read from such class is…

igr
- 10,199
- 13
- 65
- 111
2
votes
1 answer
Can anyone here explain the Kotlin/Native spinner app project structure in detail? Also the specifics on how different modules work
I would like to specifically know how the common module is used by the individual client modules. Which are the truly common parts that is shared by all the clients and the server.
Thank you.

Manoj Bisarahalli
- 91
- 6
2
votes
1 answer
Required
class TaskRepo(taskData: TaskData) {
companion object {
private val repoByTask: LRUMap = LRUMap(2, 10);
fun getInstance(taskData: TaskData): OrderFormRepo {
if (notFoundObject(taskData.taskId)) {
…

Anuj Jindal
- 1,711
- 15
- 24
2
votes
0 answers
Data Binding: ObservableField with lambda value doesn't compile
I'm trying to define the visibility of the View by calculating the lambda that takes one parameter as an argument. I'm using Kotlin, btw.
In my ViewModel I have:
val customerPropVisibility: ObservableField<(KProperty1) -> Int> =…

Sevastyan Savanyuk
- 5,797
- 4
- 22
- 34
2
votes
2 answers
How to easily consume a Kotlin channel producer in Java?
As part of working on the development of a new API, I am learning to use Kotlin. Initially I want the Kotlin API to be used within a Java (Android) project, but in the long term I hope to adopt Kotlin entirely.
As part of improving the…

Steven Jeuris
- 18,274
- 9
- 70
- 161
2
votes
1 answer
String::toByteArray() does not compile in Kotlin [js]
The following code does not compile in Kotlin Js:
"My String".toByteArray()
Any ideas why?
The error returned is:
[INFO]
[INFO] --- kotlin-maven-plugin:1.1.51:js (compile-js) @ client ---
[INFO] Kotlin version 1.1.51 (JRE 1.8.0_144-b01)
[INFO]…

auser
- 6,307
- 13
- 41
- 63
2
votes
2 answers
Java lambda type inference not working as expected in Kotlin
Why does this piece of Java code not compile in Kotlin without the explicit type parameter in Collectors.toList()? Is there a more idiomatic way to do this?
// works
List folders = Files.walk(Paths.get(args[0]))
…

atamanroman
- 11,607
- 7
- 57
- 81
1
vote
1 answer
How to resolve "Not enough information to infer type variable" when one type variable not inferrable AND using wildcard on the other?
Trying to convert some Java code to Kotlin, the Java code includes a call to a library method TableUtils.dropTable which is implemented in Java. The Java method signature of this method is
public static int dropTable(ConnectionSource…

Adam Burley
- 5,551
- 4
- 51
- 72