https://kotlinlang.org logo
Join Slack
Powered by
# general-advice
  • s

    Slackbot

    02/10/2025, 10:40 AM
    This message was deleted.
    c
    • 2
    • 1
  • c

    Caleb B

    02/24/2025, 3:58 PM
    Is there any way to "pin" generics to another type? Like have a
    Map<Class<T>, Supplier<T>>
    , where
    T
    is NOT a type parameter of the enclosing class but instead "pinning" the type of the supplier to the type of the class for runtime type validation? Instead of
    Map<Class<*>, Supplier<*>>
    and having to suppress constant type coercion warnings
    s
    • 2
    • 5
  • r

    Raj Paliwal

    02/28/2025, 5:40 PM
    Hello everyone, I am facing an issue where my app is being killed, and in the Exit Information, I see the following details: • Reason:
    OTHER_REASON
    • Description:
    ScreenOffCheckKill 26m3s4ms (26.33344%) threshold 2.0%
    The issue occurs when a*fter screen turns off, app in background.* The description in the exit logs suggests ScreenOffCheckKill, but I couldn’t find any official documentation explaining this behavior. • What exactly does
    ScreenOffCheckKill
    mean, and why does it happen? • Is this a system-level restriction or a configurable setting? • How can I prevent my app from getting killed due to this reason? • Any pointers to official documentation or similar cases would be highly appreciated. Thanks in advance for any insights!
    c
    • 2
    • 1
  • a

    Amir H. Ebrahimnezhad

    03/20/2025, 3:12 PM
    I'm struggling to publish my library on maven central repository. I use Kotlin and Gradle. Does anyone have new experience regarding this? and possibly give me instructions?
    c
    a
    • 3
    • 21
  • a

    Amir H. Ebrahimnezhad

    04/04/2025, 6:17 PM
    What's the difference between github publish maven and maven itself? I've published something on github and It cannot be found on maven server... although it seems to be published alright.
  • s

    Sebastian Schuberth

    04/05/2025, 8:16 PM
    Anyone knows whether there's a tool that can detect the issue https://www.jetbrains.com/help/inspectopedia/resource.html (unclosed
    AutoClosables
    ) but for Kotlin code and
    use
    ?
  • c

    christophsturm

    05/25/2025, 6:38 PM
    is there going to be a beta release soon that contains the new error handling?
    c
    • 2
    • 1
  • c

    Caleb B

    05/28/2025, 9:06 PM
    I'm making a tiny DSL wrapping an existing builder for a JSON deserializer library, basically adding a few macros to try to make it more declarative. I'm having trouble enabling the bundle of extension methods in the DSL block cleanly. When you're using your own builder class with a
    MyBuilder.() -> Unit
    parameter, you can obviously have the extensions be members of the builder class to be implicitly available, but I can't figure out how to do that with someone else's without making the end user either import them manually or use a
    with
    block like below. Does anyone know how I could implicitly let people use this bundle of extensions in the DSL without the
    with
    block? [Comment = original builder, code = my WIP syntax]
    c
    • 2
    • 4
  • c

    Caleb B

    06/11/2025, 8:27 PM
    Is there a way to easily make multiple names for a single function without having to redeclare them entirely? Mainly for DSL/operator purposes. For example:
    Copy code
    fun foo(arg1: String, arg2: String) {
      // ...
    }
    
    // Known:
    fun bar(arg1: String, arg2: String) = foo(arg1, arg2)
    
    // Ideal?
    fun bar = foo
    s
    • 2
    • 1
  • c

    Caleb B

    06/11/2025, 8:58 PM
    And another question: Is there any way to let a property setter accept multiple types? Again for DSL stuff. This would be so much easier if we could just make Rust-like macros, lol
    Copy code
    val default: Int
      set(value: Int) { field = value }
      set(value: IntSupplier) { field = value.get() }
    
    // so this can happen:
    mybuilder {
      // either this:
      default = 10
      // or this:
      default = { longOperationToFetchDefault() }
    }
    a
    • 2
    • 1
  • a

    aishwaryabhishek3

    06/25/2025, 6:35 AM
    Hi Folks, I wanted advice regarding structuring a sealed class hierarchy with generics, Lets say I have a sealed class with 2 child classes and one of them needs to be generic, should I make the parent class also generic or only the child class as generic. Basically which one is preferred ->
    Copy code
    // Sealed class without generics
    sealed class Result
    
    // Subclass with a generic type
    data class Success<T>(val data: T) : Result()
    
    // Subclass without a generic type
    object Loading : Result()
    Or
    Copy code
    sealed class Result<T>
    
    class Success<T>(val data: T) : Result<T>()
    
    // Some other subclass that doesn't need T can be defined as
    class Error(val message: String) : Result<Nothing>()
    j
    • 2
    • 1
  • m

    Manuel Lorenzo

    07/09/2025, 1:40 PM
    hello! I'm creating a new app and I want to use RevenueCat paywalls. However I need to facilitate Google Play store a way to test the whole app, bypassing the paywalls and I'm not sure how to do this 🤔
  • c

    Caleb B

    07/09/2025, 11:55 PM
    Is there a way to make an operator function that accepts varargs? For DSL purposes, obviously. Specifically: something like
    "foo" in ("bar", "baz", "qux")
    instead of
    "foo" in listOf("bar, "baz", "qux")
    so it doesn't read as cluttered. This one might actually be impossible since it would require
    fun (vararg T).contains
    , but it would be nice to do
    myList -= "x", "y", "z"
    c
    • 2
    • 2
  • c

    Caleb B

    07/10/2025, 12:01 AM
    Second question: I know there's a way to override the assignment operator (
    =
    ) with kotlin-assignment-plugin, but is there a way to do the same for
    is
    ? I love making DSLs. It's so much fun to screw with the language to make code more readable.
    c
    • 2
    • 1
  • k

    Kev

    08/03/2025, 7:57 AM
    Is there a way for this to know that
    decision.first
    is a
    DecisionResult.Next
    without a manual class? Its not getting inferred for some reason.
    e
    • 2
    • 2
  • a

    Amir H. Ebrahimnezhad

    08/10/2025, 4:49 PM
    I'm making a series of tutorials on Kotlin and I decided to make a fun thumbnail. As a prototype I've used Ai to make concepts and I was drawn to make a Doom style Kodee. Is drawing something like this legal?
  • g

    GeorgeS-Litesoft

    08/20/2025, 5:59 PM
    Is Kotlinlang closed to new members? Is there a process to invite new members?
    s
    g
    • 3
    • 2
  • z

    Zyle Moore

    08/29/2025, 4:44 AM
    I have a data class with some nullable
    val
    properties. It's defined in a
    core
    module. I'm using it in a
    web
    module. Sometimes it can be smart-cast to its non-nullable version, but other times it can't. I thought that if I wrap usage in an
    if (nullableProp != null) { doSomethingWith(nullableProp.toString()) }
    , it would be safe, but it's not. Browsing for answers points to cases where it's a
    var
    , which could be reassigned between dereferencing calls. Or, the other module can be recompiled(?) and not be nullable anymore. But surely, a simple data class with `val`s is safe, right? I was able to swap a `forEach`'s
    it
    with the deconstructed props, and it works fine then, so it seems like it's related to dereferencing it more than once, since deconstructing (having a single variable for the property) can smart cast, even though it's still a Public API in a different module
    c
    • 2
    • 4
  • h

    Hunter

    09/15/2025, 5:08 PM
    Is there a kmp version of java's
    unmmodifiableMap
    ?
  • j

    Jeronimo Coello

    09/16/2025, 12:53 AM
    Hi everyone, I’m trying to set up a project from scratch using Koog and Spring Boot. I have a recipe search startup and my goal is to create a first agent using Anthropic. I’ve checked Brillantov’s tutorials, but I’m running into dependency issues. Does anyone have a working
    build.gradle
    example
    that can compile and call an OpenAI or Anthropic agent with SpringBoot? I’m attaching my current
    build.gradle
    , the service class I’m using, and the error I’m seeing. Beyond this error, I’ve had several other dependency issues and tried different version combinations, but I haven’t managed to get a working example yet. What I need right now is just a minimal
    build.gradle
    with up-to-date dependencies
    that lets me call an LLM successfully. Thanks in advance! 🙏
    build.gradle.ktsRecipesAgent.kt
    • 1
    • 1
  • d

    David Beer

    09/25/2025, 12:13 PM
    Hi All, sorry if this the wrong place. I am trying to use DataFrame to output some data from a list of results. I want to use select to get only certain columns. My issue is that the DSL method doesn't want to let my code compile or recognise the column names. I used the following blog post as an example https://blog.jetbrains.com/kotlin/2024/07/enhanced-column-selection-dsl-in-kotlin-dataframe/#selecting-by-index. This works fine
    rawUserData.select { cols(0..2) }.head(3)
    but the following doesn't `rawUserData.select { firstName and address.cols("city", "state")}.tail()`the compiler can't find the values firstName and insits on import some other address value.
    • 1
    • 1
  • m

    Marvin

    09/26/2025, 12:09 PM
    Hi, I'm making endpoints from the mysql database to a webserver, but I have this error Unable to resolve table 'afstanden_woonkernen'
    Application.kt
  • j

    Justin Tullgren

    09/29/2025, 2:44 PM
    Hello, not sure if this is the right channel or not, please let me know if there is another. If we use a newer Kotlin Compiler (say 2.2+) / Gradle Plugin in a project that produces a library (klib or jar, doesn’t matter) if we want it to be compatible with Kotlin 2.1 (a previous version) if we set the languageVersion and apiVersion to 2.1 will a consuming project using an older compiler (2.1) be able to use it without throwing an error saying the library was built with a newer version?
    m
    e
    • 3
    • 23
  • s

    Stephcraft

    10/06/2025, 8:47 PM
    Is it really not possible to use Kotlin/Native to compile to and execute
    windows-x86_64
    on Windows 11 ARM 64?! Is there anyway I can 'override' a property to allow this?
    build.gradle.kts
    Copy code
    plugins {
        kotlin("multiplatform") version "2.2.20" // "2.0.0"
    }
    
    repositories {
        mavenCentral()
    }
    
    kotlin {
    
        // windows
        mingwX64("native") {
            binaries {
                executable {
                    entryPoint = "main"
                }
            }
        }
    
        sourceSets {
            val nativeMain by getting
        }
    }
    Error:
    Copy code
    Execution failed for task ':commonizeNativeDistribution'.
    > Could not isolate value org.jetbrains.kotlin.gradle.targets.native.toolchain.NativeVersionValueSource$Params_Decorated@26bb7cb5 of type NativeVersionValueSource.Params
       > Could not resolve all files for configuration ':kotlinNativeBundleConfiguration'.
          > Failed to transform kotlin-native-prebuilt-2.2.20-windows-aarch64.zip (org.jetbrains.kotlin:kotlin-native-prebuilt:2.2.20) to match attributes {artifactType=zip, kotlin.native.bundle.type=DIRECTORY, org.gradle.status=release}.
             > Could not find kotlin-native-prebuilt-2.2.20-windows-aarch64.zip (org.jetbrains.kotlin:kotlin-native-prebuilt:2.2.20).
               Searched in the following locations:
                   <https://repo.maven.apache.org/maven2/org/jetbrains/kotlin/kotlin-native-prebuilt/2.2.20/kotlin-native-prebuilt-2.2.20-windows-aarch64.zip>
    
    Possible solution:
     - Declare repository providing the artifact, see the documentation at <https://docs.gradle.org/current/userguide/declaring_repositories.html>
    References: • https://repo.maven.apache.org/maven2/org/jetbrains/kotlin/kotlin-native-prebuilt/2.2.20/ • https://www.jetbrains.com/help/kotlin-multiplatform-dev/compose-compatibility-and-versioning.html#supported-platforms • https://youtrack.jetbrains.com/issue/KT-68504/Kotlin-Native-mingwArm64-target-support • https://youtrack.jetbrains.com/issue/KT-48420/Kotlin-Native-Support-win-arm64-host
    e
    • 2
    • 3
  • v

    Vivek Modi

    10/15/2025, 3:13 PM
    Hey team, I was reading a few articles about Compose and View interoperability, and some people mentioned benchmarking to identify performance differences when using Compose within existing View-based screens. I haven’t done any benchmarking before, so I wanted to ask — what specific areas are usually measured in such cases? For example: • Rendering or layout inflation time • Frame rendering and jank rates • Recomposition or invalidation overhead • Memory and CPU usage differences Are there any other key metrics we should look at to pinpoint performance issues more accurately? Also, if you know any good learning resources, tools, or examples to understand how to write or run these benchmarks (especially for Compose), I’d really appreciate your suggestions. Thanks! 🙏
  • s

    Slackbot

    10/16/2025, 7:09 PM
    This message was deleted.
    h
    c
    • 3
    • 2
  • m

    Max

    10/19/2025, 11:50 AM
    Is there anything that will convert Kotlin down to Java, I know it goes the other way via intellij and I always assumed you could do the reverse if need be but it does not seem like you can?
    s
    • 2
    • 2
  • a

    Aadarsh

    10/21/2025, 5:52 AM
    Can I ask for job opportunities
    a
    • 2
    • 1
  • s

    Shaun Wild

    10/24/2025, 5:39 PM
    What would the best approach be to: create a processor, which converts classes into DSLs, for example, for a given data class, I want to create a DSL which allows me to build instances of that class.
    c
    • 2
    • 1
  • c

    Chris

    10/28/2025, 9:34 AM
    Hi. I'm getting compilation errors on a freshly opened copy of the "coroutines and channels" course. I opened it via Intellij IDEA and ran
    main
    and then I was presented with this:
    Copy code
    Kotlin: kotlinc-jvm 1.8.20 (JRE 24.0.2+12)
    Kotlin: [Internal Error] java.lang.NoSuchMethodError: 'org.jetbrains.kotlin.com.intellij.psi.PsiElement org.jetbrains.kotlin.resolve.lazy.data.KtClassLikeInfo.getScopeAnchor()'
    	at org.jetbrains.kotlinx.serialization.compiler.resolve.KSerializerDescriptorResolver.addSerializerImplClass(KSerializerDescriptorResolver.kt:75)
    	at org.jetbrains.kotlinx.serialization.compiler.extensions.SerializationResolveExtension.generateSyntheticClasses(SerializationResolveExtension.kt:78)
    	at org.jetbrains.kotlin.resolve.lazy.descriptors.LazyClassMemberScope.getNonDeclaredClasses(LazyClassMemberScope.kt:287)
    Must be some sort of version mismatch but I didn't change the versions in the supplied
    build.gradle
    . Is this an issue with newer versions of IDEA?