https://kotlinlang.org logo
Join Slack
Powered by
# general-advice
  • 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?
  • s

    Shaun Wild

    11/05/2025, 11:57 PM
    Is anyone able to take a look at this? Not being noticed, and really need some help here.
  • j

    Jack Eblan

    11/06/2025, 8:46 AM
    Hello team, I was wondering if we could find a workaround, since the package-private concept isn’t supported in Kotlin. In Jetpack Compose, I have a Composable function that’s about 1,000 lines long. I’d like to extract some of its components into separate files so they’re easier to find within the package, rather than scrolling through the entire file to locate specific functions. Extracting them into a separate module feels like overkill — they’re already part of a cohesive feature module. I just don’t want those extracted components to be public. I’ve seen some workarounds, such as creating a custom lint rule, but I hope we can consider an official approach for this.
    s
    h
    s
    • 4
    • 3
  • s

    spand

    11/06/2025, 9:54 AM
    Say I have a RequiresOptIn annotation called
    @LegacyApi
    . Can I create a super class ie.
    LegacyApiRequestHandler
    that "OptIn" on behalf of its subclasses ?
    e
    • 2
    • 1
  • j

    Jovan

    11/06/2025, 12:31 PM
    Hello everyone, I'm trying to understand if there is a difference between
    Map.entries.forEach
    and
    Map.forEach
    Calling entries can be expensive, not sure if second example does the same behind?
    c
    • 2
    • 2
  • r

    Rob Elliot

    11/07/2025, 1:09 PM
    Slightly bizarre question, but has anyone written a transpiler from Kotlin to Java? My thinking is that for a lot of JVM libraries it's nice not to have an extra stdlib on the classpath, locking you into a Kotlin version, extra bytes to download, risking the ire of Java devs who hate that particular other JVM language for whatever reason... But it would be nice to write them in Kotlin 🙂. So what if there were a transpiler that would turn your Kotlin into really nice idiomatic Java as a build step?
    e
    • 2
    • 5
  • n

    Nana

    11/09/2025, 7:55 PM
    Hey folks, wanted to try and contribute to the efforts of 1. bazel support for kmp 2. first class ui-library that supports native look and feel for all the multiplatform platforms (if that is a thing) - especially with the issues of how liquid glass cannot see kmp New to helping out with projects like these - so will look around the slack for a bit first! Excited to contribute!
  • g

    Gautamesh Zope

    11/10/2025, 1:24 AM
    Hey guys, I need help in http requests with the ktor client
    r
    • 2
    • 1
  • t

    Talha Chaudhry

    11/13/2025, 4:10 PM
    I faced a very weird issue today, In my commonMain I defined an enum Map i.e. Map<Enum1,Enum2> for android side things worked as expected but for iOS side Map was populated when I tried to get value against key it always returns null even though I verified the Map entries and key via logs
  • s

    Shaun Wild

    11/16/2025, 3:49 PM
    What's going on here? I posted this issue two weeks ago and haven't so much as an acknowledgement? https://youtrack.jetbrains.com/issue/KTIJ-36331/Context-sensitive-resolution-does-not-resolve-correctly-in-IDE-in-Kotlin-Scripts
    r
    • 2
    • 2
  • a

    Abhilash Mandaliya

    11/17/2025, 4:52 PM
    Hello everyone. I am looking for some blog explaining benefits of Java 21 for the Kotlin server side development. Our project uses Kotlin 2.2.x with Java 11 runtime. Instead of directly comparing performance between Java 11 and Java 21, I want to understand how all new features of Java 21 really impact Kotlin based server side application. Thanks in anticipation 🙏