https://kotlinlang.org logo
Join Slack
Powered by
# forum
  • r

    rss

    05/08/2025, 11:39 AM
    Is Maven a Viable Replacement for Gradle in Kotlin Development? I have a low-spec potato laptop (i3 gen 3 2ghz with 8gb ram), and I’ve tried using Gradle with IntelliJ—it felt like my laptop was about to explode. I looked for alternatives and tried Gradle with VSCode. This time it didn’t feel like it was going to explode, but it was still very heavy. Finally, I tried Maven with VSCode, and with this setup, my laptop ran normally like usual. My question is: is it okay to develop Kotlin using the Maven build system? From what I’ve read, Kotlin is very...
  • r

    rss

    05/09/2025, 2:59 AM
    suspendCoroutine COMPLETELY BROKEN? I have tried the following code: Kotlin Playground Kotlin Playground: Edit, Run, Share Kotlin Code Online Explore Kotlin and practice your coding skills on the Kotlin Playground! Simply type a snippet of code and click Run to try it on the fly....
  • r

    rss

    05/09/2025, 10:39 AM
    Parameter and method precedence I had this (very simplified) code: // In a generic lib interface ISerializer { //... } // In a project using this lib class MySerializer : ISerializer { fun writeMyBlock(name: String, exp: ISerializer.() -> Unit) { //... exp() //... } } Months later, in the generic lib, I simply add a method in my interface (unfortunately, I choose exp as name): // In a generic lib interface ISerializer { fun exp(vararg s: String) { //... } } Some of my projects are then silently buggy: The...
  • r

    rss

    05/10/2025, 9:39 AM
    Access value by type with any kind of data structure Suppose I need to keep three numbers of Int, Long and Float in a bunch, and access these numbers by their type. First idea is to use HashMap, where key is type of number, and value is number itself. val bunch = mapOf( Int::class to 0, Long::class to 0L, Float::class to 0f, ) But in this case Kotlin does not inference needed value type, and I need to use explicit cast. val i: Int = bunch[Int::class]!! // Error: Initializer type mismatch: expected 'Int', actual 'Number'. val f:...
  • r

    rss

    05/10/2025, 4:19 PM
    Infer type from filterIsInstance Having interface sealed interface Param { val value: T @JvmInline value class Power(override val value: Float) : Param @JvmInline value class Income(override val value: Float) : Param } I put some instances of it to a list val params = listOf( Param.Power(1f), Param.Income(2f) ) Then I want a function, which should return value of a parameter by it’s type, like inline fun get() = params.filterIsInstance().first().value But this one does return Any? instead...
  • r

    rss

    05/11/2025, 5:59 AM
    Ghee in the morning is one more than one of the day of lord Krishna is one more than one of my friends and I Dud e Number of lord Krishna is the world of lord Shiva is the world of the world of the world of the world of the world of the world of lord 1 post - 1 participant Read full topic
  • r

    rss

    05/16/2025, 3:19 PM
    Connecting to Mariadb database Please can I have an example of connecting to a maria/mysql database I have tried many examples/tutorials to no avail. 1 post - 1 participant Read full topic
  • r

    rss

    05/19/2025, 6:49 AM
    Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.9.9999, expected version is 1.7.1 Hello everyone, despite hours of searching on Google and lots of try&error in Android Studio, I can’t find an explanation that I can understand as to where this error comes from and how I can fix it. I get this message for several modules: C:/Users/eltern/.gradle/caches/8.14/transforms/087a1e2dbf168d190aaf77e16d43e487/transformed/navigation-fragment-2.9.0-api.jar!/META-INF/navigation-fragment_release.kotlin_module: Module was compiled with an incompatible version of Kotlin. The binary...
  • r

    rss

    05/21/2025, 8:29 AM
    Request invite in Slack not working (topic deleted by author) 1 post - 1 participant Read full topic
  • r

    rss

    05/26/2025, 2:59 PM
    Improve type inference for types with common type parameters I tried various ways of having a single hierarchy to use for “tagging” and using it to infer the member types of arbitrary “aggeragates” of data I’d like to be related by a type parameter, and ran into various inference limitations: open class Wrapper( val value: T, ) class IntWrapper( value: Int, ) : Wrapper(value) class AnotherWrapper( val value: T, ) class WrappersHolder( val a: Wrapper, val b: Wrapper, val c: AnotherWrapper, val d: T, ) fun test() { val...
  • r

    rss

    05/28/2025, 10:49 AM
    DateTime design probably needs a rework Kotlin doesn’t provide in the stdlib any support for datetime operations, even if in most real-world applications this datatype is very much used. To perform computations, you need to download an external dependency and import kotlinx.datetime. The name of the basic DateTime object is LocalDateTime, which is a reference to the name Java used to fix Java’s broken Date /Calendar API. However, it doesn’t behave the same and requires manual casting to convert them. This leads to serialization...
  • r

    rss

    05/29/2025, 1:49 PM
    Polymorphism based on sealed class Consider the following: sealed class Base class A: Base() class B: Base() fun doSomething(thing: Base) { when (thing) { is A -> doIt(thing) is B -> doIt(thing) } } fun doIt(a: A) { println("A") } fun doIt(b: B) { println("B") } The body of doSomething seems a little silly at first glance, because it calls doIt(thing) in both cases. However, the following does not compile: sealed class Base class A: Base() class B: Base() fun doSomething(thing: Base) {...
  • r

    rss

    06/03/2025, 6:59 PM
    Can I make this algorithm faster? I have this code: fun main() { measureTimeMillis { LongStream.rangeClosed(1, 1_000_000) .parallel() .mapToObj(BigInteger::valueOf) .reduce(BigInteger::parallelMultiply) .getOrNull() }.run { println(this) } } It calculates factorial in about 900ms. Today I’ve seen similar code in Rust that takes about 80ms to calculate. Is there some way to make my code faster? Maybe some external libraries or whatever… 1...
  • r

    rss

    06/04/2025, 3:19 PM
    Howto re-order my buttons? Hi All, I’m new to Kotlin. I made an app for displaying Jazz sheets. But now I want the 35 presenting buttons re-order, so it’s alphabetical correct. Replacing the ‘button-blocks’ in XML did not the trick. I assume it must be very simple … Thnx. <a class="lightbox" href="

    https://us1.discourse-cdn.com/flex019/uploads/kotlinlang/original/2X/3/3af706440ad2b97197b3ea4c67a18d4ca9ae1ce9.png▾

    " data-download-href="/uploads/short-url/8pCWknhig20BzueWFMQhiQe9t1v.png?dl=1" title="image" rel="noopener...
  • r

    rss

    06/06/2025, 12:29 PM
    How to use compose-multiplatform-resources in KMP SwiftUI? How to share resource id and call from swift UI in KMP? Is this possible CMP lib in KMP? Example below given in Using multiplatform resources in your app | Kotlin Multiplatform Documentation coroutineScope.launch { val appName = getString(Res.string.app_name) } 1 post - 1 participant <a...
  • r

    rss

    06/07/2025, 11:09 AM
    Make overloading of inline functions smarter It is a well known fact that functions can be only differentiated by arguments, but not by return type or type parameters. Inline functions are by definition, well, inlined, so in theory such considerations shouldn’t apply. Take this example: inline fun tuple(): Pair = "red" to "white" inline fun tuple(): Triple = Triple("red", "green", "blue") var x = "green" to "blue" ... x = tuple() // returns Pair("red", "white") This doesn’t compile, but I see no good reason to disallow it. Same for...
  • r

    rss

    06/07/2025, 5:09 PM
    What’s the Real State of Kotlin Desktop / Compose for Desktop? Hi everyone, Lately, I’ve been exploring Kotlin Multiplatform and Compose for Desktop. I’m particularly excited about the idea of writing desktop apps in Kotlin. But the deeper I dive, the more it feels like I’ve landed in a bit of a strange spot: What’s the actual state of Compose for Desktop right now? Is JetBrains (or the community) actively working on desktop-first components? Where can I find production-ready UI patterns for real-world use cases? Is Jewel (JetBrains’ UI toolkit)...
  • r

    rss

    06/07/2025, 8:29 PM
    About property getters Consider this: class SomeClass { val someProperty: SomeType get() { /* ... */ } } Why not have property getters without parentheses? Something like: class SomeClass { val someProperty: SomeType get { /* ... */ } } Thank you for your attention, João 1 post - 1 participant Read full topic
  • r

    rss

    06/08/2025, 12:29 PM
    Mikrator (a Liquibase wrapper): changelogs as code, easy usage I always wanted to integrate a database migration tool, like Liquibase, into projects. But I didn’t quite like the untyped changelog files or some APIs. I love Kotlin DSLs and static typing, so I had the idea of creating a wrapper that supplies both. Here is the first PoC alpha version of that: GitHub - Batix/mikrator: A Liquibase wrapper for easy usage and changelogs as code. To save you a...
  • r

    rss

    06/11/2025, 8:39 AM
    Kotlin insiders, can you help? Hi, I am starting my Kotlin journey and trying some easy (as easy as Kotlin seems to be) codes for things that come to my mind. I tried to make this code for adding two fractions together. Sorry for making the names so long I still want to keep it detailed for my own comfort of learning. import kotlin.math.abs fun main() { println(“Enter the first fraction (e.g. 1/2):”) val fraction1 = readLine() ?: “” println(“Enter the second fraction (e.g. 1/3):”) val fraction2 = readLine() ?: “” val...
  • r

    rss

    06/11/2025, 9:39 AM
    Help someone? Can you tell me how to simpilfy this code class FractionSimplifier(private val ulamek: String) { private fun nwd(a: Int, b: Int): Int { var aa = a var bb = b while (bb != 0) { val temp = bb bb = aa % bb aa = temp } return aa } fun simplify(): String { val (licznik, mianownik) = ulamek.split("/").map { it.toInt() } val dz = nwd(licznik, mianownik) return "${licznik / dz}/${mianownik / dz}" } }? 1 post - 1...
  • r

    rss

    06/11/2025, 5:49 PM
    How to make rows the same length with Compose I am trying to use IntrinsicSize.Max to make Rows the same length but it is not working for my code. I tried weight(1f) also but did dot worked either. The rows are ignoring the weight and IntrinsicSize code but instead are being wrap to content width. The following is the relevant code: Column( modifier = Modifier .fillMaxWidth(), verticalArrangement = Arrangement.Center ) { LazyColumn( state = lazyState ) {...
  • r

    rss

    06/16/2025, 10:19 PM
    WEBSocket + KTOR Hello everyone I have a small issue and I don’t know how to fix, I have the following code to set up my WebSocket. I’m trying to build a chat, and I store my sockets in a repository so that when client1 sends a message to client2, I can notify client2 via their WebSocket if they are connected. My problem is the following: if I turn off the internet on the mobile side for about 3 minutes, my socket is no longer active, probably because the ping/pong fails. However, the finally block is never...
  • r

    rss

    06/24/2025, 7:29 AM
    Provide a way to avoid GC safepoint I want to writing a library just like java.lang.ProcessBuilder But I found it’s difficult to complete the project in pure Kotlin. When I executing the following code, it’s hang… val pid = fork() if(pid == 0) GC.collect() else println(pid) The new process(pid != 0) was hang on the GC collection… Personally I don’t like the fork-exec, I prefer posix_spawn. But I found there’s no posix_spawn_file_actions_addchdir, which was published in POSIX 2024… 1 post - 1 participant...
  • r

    rss

    06/26/2025, 1:09 PM
    Badexec errors in ios function MemoryManager.updateMemoryStatus() kotlin.native.runtime.GC.collect() timeStamp().also { timestamp-> runCatching { CMSampleBufferGetImageBuffer(didOutputSampleBuffer).also { buffer -> CVPixelBufferGetWidth(buffer).also { w -> CVPixelBufferGetHeight(buffer).also { h -> CIImage.imageWithCVPixelBuffer(buffer).also { imageBuffer ->...
  • r

    rss

    06/29/2025, 10:59 AM
    Failed https://dl.google.com/dl/android/maven2/com/google/ When trying to create a project in Android Studio, the download logs consistently show about 30-60 downloads failing. Example: Failed https://dl.google.com/dl/android/maven2/com/google/protobuf/protobuf-java/3.25.5/protobuf-java-3.25.5.pom 37 ms 0 B 0 B/s In the browser (when clicking on the direct link), a 404 error comes up. And in Sync these...
  • r

    rss

    06/30/2025, 3:19 AM
    Issue Intercepting JavaScript-Based Navigation in Android WebView (Blank Screen on Link Click) I’m trying to intercept navigation within a WebView. The problem occurs when a link is clicked — the website runs JavaScript that causes the screen to go blank, even though I’m intercepting the navigation using shouldOverrideUrlLoading, shouldInterceptRequest, and other methods. I’m certain it’s an issue with the specific website, as other sites do not exhibit this behavior. What confuses me is that iOS handles it correctly — using webNavigationAction, it seems to block the navigation before...
  • r

    rss

    06/30/2025, 1:59 PM
    Google MLKit for ios Has anyone managed to successfully integrate an iOS MLKit into a compose multiplatform project? I have tried everything I can think of to no avail 1 post - 1 participant Read full topic
  • r

    rss

    07/03/2025, 9:59 AM
    .filter after if else if else does not work on first if Greetings! Help me please undestand why this piece of code does not do what I expect it to do. Code snippet class SandboxKtTest { @Test fun test() { val a = 4 val name = if (a < 5) { listOf(3,5,7) } else if (a >5) { listOf(1,2,3) } else { emptyList() }.filter { it == 3 } println(name) } } Expectations: the result is [3] Actual: the result is [3,5,7]. Observations: if i...
  • r

    rss

    07/04/2025, 7:59 AM
    Why does Kotlin allow member and extension function with same signature? Kotlin allows both member functions and extension functions to coexist even if they have the same signature. Why did Kotlin allow this and decide not to show error during compilation? This makes the existing code fragile during dependency updates. 1 post - 1 participant Read full topic