Questions tagged [kotlin-interop]

Usage of Kotlin together with other languages, most notably Java. e.g. Calling Kotlin functions from Java, or using Java classes from Kotlin.

117 questions
5
votes
0 answers

Kotlin SAM conversion with private inner Java interface?

Consider the following Java class: package javapkg; public class JavaClass { private interface JavaInterface { void foo(); } public void bar(JavaInterface ji) { ji.foo(); } } Kotlin code that uses this class's…
josmith42
  • 848
  • 2
  • 10
  • 18
5
votes
1 answer

Override setter for variable defined in default constructor

So I have a Kotlin class that looks something like this: class MyClass { var myString: String = "" set(value) { field = value doSomethingINeed() } constructor(myString: String) { this.myString…
AdamMc331
  • 16,492
  • 10
  • 71
  • 133
5
votes
3 answers

Kotlin compiler's type inference can't choose which method to call (ambiguity with generic types)

So, I have some Java methods with these signatures (removed annotations and code body for the sake of simplicity): public class JavaClass { public static E join(E... array) { ... } public static
4
votes
2 answers

Include Kotlin/Native KDocs documentation in built .frameworks for iOS/XCode

I'm developing a Kotlin/Native library for both iOS and Android. When running ./gradlew assemble I get the release/debug .frameworks with Obj-C Headers. I can use these .frameworks fine. But I would also like to carry on with documentation of…
4
votes
1 answer

Kotlin/Native: How to convert cArrayPointer to Array

How can I convert cArrayPointer to a simple Array/List when using c-interop? val myArray: Array = memScoped { val cArray = allocArray(5) fill(cArray) cArray.toSimpleArray() <--- There is no such function }
Feedforward
  • 4,521
  • 4
  • 22
  • 34
4
votes
3 answers

Migrate Java Option call to kotlin

I'm taking my first steps with kotlin. I am migrating some my existing java code to kotlin. I have the folllowing line: storyDate.ifPresent(article::setPublishDate); Where storyDate is an Optional and article has a method setPublishDate(Date)…
Michael Wiles
  • 20,902
  • 18
  • 71
  • 101
4
votes
2 answers

How to make a data class in Kotlin immutable with java Date object in it?

The java.util.Date itself is a mutable object. As such even if Kotlin data class (with date field declared val) prevents me from changing the reference I can modify the date object itself to change its value. Ways I could come up with: Use normal…
faizan
  • 578
  • 5
  • 14
4
votes
1 answer

Kotlin dagger 2 Android ViewModel injection error

I'm trying to use dagger 2 on my Android application to inject the new ViewModel from arch android library. From what I see on this sample…
jaumard
  • 8,202
  • 3
  • 40
  • 63
3
votes
0 answers

Kotlin/Native GTK Interop

I have a def file File contents: headers = gtk/gtk.h package = gtk headerFilter = gtk/* gobject/* gio/* gdk/* glib/* gdk-pixbuf/* compilerOpts = -I/usr/include/ -I/usr/include/gtk-3.0/ -I/usr/include/x86_64-linux-gnu/…
3
votes
1 answer

Converting Java To Kotlin: Type mismatch. Required: MenuSlidingTabStrip.OnTabSelectedListener? Found: (Nothing, Nothing) → Boolean

I am converting an Android app that was originally written in Java to Kotlin. I am struggling to understand the following error message: Type mismatch. Required: MenuSlidingTabStrip.OnTabSelectedListener? Found: (Nothing, Nothing) → Boolean Here…
Amon Chepri
  • 87
  • 2
  • 7
3
votes
2 answers

Compile time error in passing vararg parameter to another function in Kotlin

I'm trying to accept a vararg parameter as a function parameter in Kotlin and trying to pass it to another function with vararg parameters. However, it gives me a compile time error in doing so, type mismatch: inferred type is IntArray but Int was…
Pinaki Acharya
  • 339
  • 3
  • 11
3
votes
1 answer

How to run Clojure in Kotlin?

Is it possible to run clojure in kotlin? More specific in spring? I have made scrapers in clojure and I want to use them on a web application written in kotlin. How does that look like in kotlin? The code..
3
votes
3 answers

Kotlin generic Out-projected type prohibits the use of

I'm using kind of dynamic form system coming from the backend. To be able to map my form I have a visitor pattern with generics, I have it working in Java but I can't make it to work in Kotlin. I have this interface: internal interface…
jaumard
  • 8,202
  • 3
  • 40
  • 63
3
votes
2 answers

How can I declare a function parameter that can be a string or a function, in Kotlin?

In the following function, I want to pass to it attributes for a html tag. These attributes can be strings (test("id", "123")) or functions (test("onclick", {_ -> window.alert("Hi!")})): fun test(attr:String, value:dynamic):Unit {...} I tried to…
dilvan
  • 2,109
  • 2
  • 20
  • 32
3
votes
1 answer

Architecture of own SDK - async method API in Kotlin

We are building a public SDK for our product. It is built with Kotlin and internally we use coroutines. However, we want to publish an API that is usable form JAVA, that's why can't provide suspendable functions as public API. We are ok, if the…
hrach
  • 2,443
  • 2
  • 26
  • 37