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
1
vote
1 answer

What's the use for Kotlin's @JvmSynthetic on a file target?

The @JvmSynthetic annotation is allowed to be used on a file, but I can't figure out what the purpose of this would be. I was hoping I could hide a file containing a bunch of Kotlin-only extension methods from Java users, but that doesn't seem to be…
1
vote
1 answer

How can an exhaustive when throw NoWhenBranchMatchedException?

I observe a LiveData with an exhaustive when statement, how can it throw a NoWhenBranchMatchedException at runtime? Wasn't exhaustiveness checked for at compile time? enum class MyEnum { Foo, Bar } liveData.observe(viewLifecycleOwner) {…
1
vote
1 answer

Kotlin Multiplatform - Objective-C interoperability architecture issue Undefined symbols for architecture x86_64

I just tried using native interop feature since I need native code written in Objective-C to be used in my library. So first I'm trying to test using simple hello to interop an Objective-C code gradle : kotlin { ... val iosX64 =…
1
vote
2 answers

Differences in writing Kotlin/JVM and Kotlin/JS?

I read the Big Nerd Ranch guide to Kotlin and it talked in several places about Kotlin/Java interop, but never JS or native. I already had a solid background in Java, so I have gotten used to using Java classes in my Kotlin code. I am trying to…
Sam
  • 261
  • 2
  • 11
1
vote
1 answer

Can I know when my library is called from Java or Kotlin?

I'm developing a Kotlin library for Android. I want to provide a great developer experience for both Kotlin and Java developers, but because I don't have infinite resources I need to prioritize between those. The library is interacting with a…
PLNech
  • 3,087
  • 1
  • 23
  • 52
1
vote
0 answers

How to tell the compiler to use Kotlin extension function instead of Java 8 function for Android App

I want to use function MutableList.replaceAll(transformation: (T) -> T) in my Android project. There is a very similar question: Kotlin Extension Functions suddenly require api level 24 But is my case, I want to use the function replaceAll which…
Oknesif
  • 526
  • 5
  • 11
1
vote
0 answers

Kotlin resolution ambiguity when trying to access a field named "name" in an enum

Kotlin can't access a field in a java enum because it is called name, which collides with the name variable in Kotlin's definition of Enum, as seen in this question: Conflicting 'name' declaration in enum The solution to that question was to edit…
lbenedetto
  • 2,022
  • 1
  • 21
  • 39
1
vote
3 answers

"Unresolved Reference" when Interop-ing C Library

I am trying to make a militaristic example of reading and executing C code within Kotlin-Native. I am following this article here. However, I'm receiving an "Unresolved Reference" error on the final step. Here are all the files/commands I'm using.…
Griffort
  • 1,174
  • 1
  • 10
  • 26
1
vote
1 answer

Is there a way to hide the INSTANCE variable on a Kotlin singleton object

If I have code like this object ObjectTest { @JvmStatic fun init() { } } is it possible to hide the ObjectTest.INSTANCE variable that Kotlin automatically generates? I don't want the object to be accessible via an instance and nor will…
vanshg
  • 1,125
  • 2
  • 10
  • 19
1
vote
1 answer

Calling inner class in the parent not working in kotlin

I was in process of converting a java project to kotlin when I encountered this strange behavior. in Java: new ImageSwitcher.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); works fine. but in kotlin it…
humazed
  • 74,687
  • 32
  • 99
  • 138
1
vote
2 answers

kotlin - non null mark for platform types / methods

I often use UUID.randomUUID(). Type inferred by kotlin is UUID!. is there any way to tell kotlin that return type of this specific method is UUID and is always non null? or do i have to do everywhere UUID.randomUUID()!! or implement my own method?
piotrek
  • 13,982
  • 13
  • 79
  • 165
1
vote
3 answers

How to define Class type property using get() in Kotlin

How to define a property using get() in Kotlin which returns a class, I was trying below, but it's not compiling val targetActivity: Class get() = MyActivity.class
Akhil
  • 6,667
  • 4
  • 31
  • 61
1
vote
1 answer

Why do some Java setter methods automatically become Kotlin properties but some don't?

e.g. this WebSettings Java class. It has a Java method setJavaScriptEnabled(boolean) that turns into a Kotlin property javaScriptEnabled as below, but there is also setSupportZoom(boolean) that does not turn into a Kotlin property supportZoom. …
Randy Sugianto 'Yuku'
  • 71,383
  • 57
  • 178
  • 228
1
vote
1 answer

Smart cast doesn't work as expected

I have the following Kotlin code: fun handleResult(clazz: Any){ val store = App.getBoxStore(); if(clazz is List<*> && clazz.size > 0){ val items: List<*> = clazz; val item = items.get(0); val box =…
Allan Araújo
  • 173
  • 2
  • 13
1
vote
1 answer

How do you use Flowable.generate from Kotlin

Here's a failed stub attempt at Flowable.generate (with more type annotations than I'd normally use): val xs: Flowable = Flowable.generate( java.util.concurrent.Callable { -> 0 }, io.reactivex.functions.BiConsumer
James Moore
  • 8,636
  • 5
  • 71
  • 90