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
1
vote
1 answer
Kotlin syntax for inferring generic supertype from subtype
Trying to call existing Java code that expects a Class as a parameter, I tried code along the lines of this in Kotlin:
package com.example
//Acutally imported Java code in someone elses's library
abstract class JavaCode {
fun…

Alex Taylor
- 8,343
- 4
- 25
- 40
1
vote
2 answers
Kotlin - attribute visibility to companion object
So I have the code below, written in Kotlin.
I'm getting a compilation error on the last instruction line (return params.keys.containsAll(MANDATORY_PARAMS)), the compiler says Unsolved reference: MANDATORY_PARAMS, but I don't really get why.
I…

felipecao
- 993
- 1
- 10
- 23
1
vote
1 answer
Kotlin Vertx Type Mismatch found Future expected Handler>
I thought that in Kotlin, Unit was equivalent to Void. With Vert.x Service Discovery, it is not possible to pass a Future to unpublish(String id, Handler> resultHandler) (gives a type mismatch) yet it will accept Future…

junglie85
- 1,243
- 10
- 30
1
vote
0 answers
Access fields from interface in an object in Kotlin
I've started to convert some of my code from Java to Kotlin.
Some of these are database schema classes, containing constants for the different column names (I'm working with Android here).
I've modified my Java final class with static constants, so…

Farbod Salamat-Zadeh
- 19,687
- 20
- 75
- 125
1
vote
1 answer
Platform Declaration Clash with Comparable
I'm getting a Platform Declaration Clash error from the compiler resulting from multiple default implementations of the Comparable interfaces (demonstrated below).
interface ClassA: Comparable
{
val x: Int
get
override fun…

desilvai
- 331
- 3
- 9
1
vote
2 answers
Jinq in Kotlin - how to convert lambda into java SerializedLambda?
Can I have serializable lambda in Kotlin? I am trying to use Jinq library from Kotlin, but it requires serializable lambdas. Is there any syntax that makes it possible?
Update:
My code:
var temp=anyDao.streamAll(Task::class.java)
…

vinga
- 1,912
- 20
- 33
0
votes
3 answers
how to make kotlin interface property with default value to be used in java code
Using kotlin 1.6.21, and java 11.
Having a kotlin interface which has property with default value. How to make use it in java code?
interface ISomeKInterface {
val flag: Int
get() = return 1
fun onProc(data: String) {
if (flag…

lannyf
- 9,865
- 12
- 70
- 152
0
votes
1 answer
Kotlin Objective-C interop usage of Protocol initialization in Kotlin interface
I just tried to use my compiled staticLibrary using objective-c code.
here's what inside my nativeLib.a :
NativeHello.h
#import
@protocol NativeDelegate
- (void) test: (NSString *)strData;
@end
@interface NativeHello:…

Davin Reinaldo Gozali
- 151
- 1
- 15
0
votes
1 answer
Dealing with (U)Int in Kotlin Native C interop
I'm trying to use the PiGPIO library with Kotlin Native as a linked library (not using the deamon).
So I'm using C interop with a .def file that references the pigpio.h file.
It works (I managed to get a LED blinking) but there is an issue with…

herman
- 11,740
- 5
- 47
- 58
0
votes
1 answer
kotlin: how to overload imported function
i use assertj. among others it has functions assertThat(int) and assertThat(Object). i would like to add my own function
fun assertThat(flux: Flux) = assertThat(flux.toStream())
but then it seems like i can't easily use it. when i declare…

piotrek
- 13,982
- 13
- 79
- 165
0
votes
1 answer
How to disable @NonNull/@Nullable annotations in Kotlin generated Java code
I need to disable @NonNull/@Nullable annotations in Kotlin generated Java code because some annotation adapters (code generators) cant handle properly some annotated fields
Do you know how it could be done? Some Kotlin annotation or compilator…

Filipkowicz
- 639
- 6
- 17
0
votes
1 answer
how to define class in kotlin with member can be accessed in java derived class
Having a class defined in kotlin, with members
@JvmField protected val clickHandler: BaseClickHandler
@JvmField protected var layoutId : Int
but when in java trying to extends this class and access the member it gets error.
interface ViewDelegate…

lannyf
- 9,865
- 12
- 70
- 152
0
votes
4 answers
can we swap two numbers in kotlin using two variables and take input from user?
I tried it by the following program but it shows the error that kotlin variable is expected:
[

Varun Gandhi
- 1
- 2
0
votes
0 answers
Cannot return and assign multiple values in kotlin
I am new to Kotlin and I wanted to return multiple values from a function.
I checked this post:
How do we return multiple values from a function in Kotlin like we do in swift?
I am using a recursion function where I don't have to use var or val…
user9858113
0
votes
0 answers
Why no compile error when passing kotlin class to a Java function constrained by java generics?
I'm having trouble enforcing type safety when using kotlin with Java.
Please see the code snippets below showing setup, the lack of compile error is the issue.
// kotlin functions
inline fun k() = T::class
// A is a Java…

newlogic
- 807
- 8
- 25