https://kotlinlang.org logo
Join Slack
Powered by
# getting-started
  • y

    y

    10/29/2025, 2:25 PM
    I have
    fun <T> foo1(vararg elements: Iterable<T>) = /* ... */
    I also have
    fun foo2(vararg elements: List<Bar>)
    what exactly happens when I call
    foo1(*elements)
    from within
    foo2
    ? what does the spread operator do here? is this zero cost?
    y
    c
    • 3
    • 8
  • b

    Bernhard

    10/30/2025, 9:40 AM
    I'm trying to convert a while(x.hasNextPart()) loop into a sequence; so far I've found generateSequence but I'd need to bundle up the hasNext boolean so I can stop, e.g.
    generateSequence { Elem(it.hasNextPart())}.takeUntil {it.hasNext}
    is there a better way to do that? and in that case, would you prefer an Iterator instead?
    ✅ 1
    K 1
    j
    • 2
    • 3
  • g

    Gasan

    10/31/2025, 10:44 AM
    Dear all. Why does Kotlin force parameter variables to be constants,
    val
    ? Kotlin does not have a concept of a "pointer to a const", therefore I can change the referenced value, unless it is immutable. I mean,
    val
    parameter variable does not amount to much unless the referenced value is immutable.
    v
    s
    +4
    • 7
    • 60
  • u

    ursus

    11/01/2025, 12:50 AM
    When valhalla drops, I assume it will introduce new byte code, so kotlin compiler will need to be updated to emit such bytecode But what about android? I'd assume ART needs to implement such new bytecode -- does that mean the new true value classes will be bound to latest android version?
    e
    g
    • 3
    • 12
  • y

    y

    11/03/2025, 9:44 AM
    apologies in advance for the complexity here. trying to debug the following exception:
    Cannot invoke "java.util.Map.get(Object)" because the return value of "A.getMethods()" is null
    which we seem to get, but only sometimes. we have this: (
    A
    ,
    B
    ,
    C
    are all concrete classes, renamed to anonymize)
    Copy code
    abstract class A(/* ... */) : Lots, Of, Things {
        abstract override val methods: Map<B?, C>
        abstract override val someMethod: C?
        /* ... */
        override fun getMethods(): List<C> = methods.values + listOfNotNull(someMethod)
    }
    what could be the issue here? is it an order of initialization thing? is it related to the choice of the name
    getMethods
    ? (since kotlin desugars getters to that name, no?)
    s
    b
    h
    • 4
    • 7
  • c

    CLOVIS

    11/03/2025, 5:12 PM
    Is there any distinction, in Kotlin, between signalling and quiet NaNs?
    e
    • 2
    • 9
  • j

    Jack Boyce

    11/04/2025, 7:59 AM
    Hi, I'm an absolute beginner going through the Compose Multiplatform demo app. I got it to build and run for all of the targets except for Android, where I get the attached error message "please select Android SDK". Under File->Project Structure->SDKs I have Android API 36.0, extension level 17 installed. Is there somewhere else I'm supposed to set the Android SDK? Thanks!
    j
    • 2
    • 14
  • b

    Bernhard

    11/04/2025, 11:58 AM
    been working a bit with KTOR recently and it has a fantastic URL builder that feels like it should belong into the stdlib (or at least into a kotlinx lib)
  • h

    hfhbd

    11/05/2025, 11:14 AM
    Why is it possible to pass
    null
    in Map<String, String>.get(null):
    mapOf<String, String>("f" to "f").get(null as String?)
    r
    e
    • 3
    • 4
  • e

    Edgar Avuzi

    11/08/2025, 5:52 AM
    Hi everyone, For this problem: https://leetcode.com/problems/increasing-order-search-tree/, I’m trying to write a Kotlin solution that clearly separates the logic for tree traversal order from the logic for building the resulting linked list. I did that in other languages, but I’m struggling to come up with an elegant and gibberish-free Kotlin version that doesn’t feel awkward or verbose. Combined all solutions here https://gist.github.com/Sedose/1d0ee8a6717feeb28a17aaeb4ff89080. Would appreciate any suggestions for making it good looking
    y
    • 2
    • 3
  • e

    elect

    11/09/2025, 10:55 AM
    why if I use an unamed context parameter this isn't available for resolution?
    Copy code
    import org.gradle.api.Project
    import java.io.ByteArrayOutputStream
    
    context(_: Project)
    operator fun String.invoke(vararg args: String): String {
        val output = ByteArrayOutputStream()
        providers.exec { // error, `providers` unresolved
            commandLine("arduino-cli", "version")
            standardOutput = output
        }
        return output.toString()
    }
    y
    • 2
    • 7
  • r

    Rob Elliot

    11/09/2025, 11:09 AM
    Dependabot is trying to upgrade micrometer from 1.15.5 to 1.16.0 and my Kotlin is no longer compiling:
    Copy code
    fun nullableReturn(): String? = TODO()
    
    val timer: Timer = TODO()
    
    try {
      timer.recordCallable {
        nullableReturn()
      }
    } finally {
      timer.close()
    }
    > Argument type mismatch: actual type is 'CallableString?', but 'Callable<uninferred T! (of fun T : Any recordCallable)>!' was expected.
    • 1
    • 3
  • n

    Natalia Mishina

    11/10/2025, 12:42 PM
    kodee welcoming Hey everyone! If you’ve just started learning Kotlin (or are about to) — we’d love to hear from you! 💬 The Kotlin team is running a diary study to learn how developers onboard to Kotlin — what the first steps look like, what challenges come up, and what helps you make progress in the Kotlin ecosystem. 🗓️ The study runs for 3–4 weeks and includes: • an intro call (15–20 min); • a simple diary in Google Docs; • a debrief interview (~40 min). If this sounds like you, fill out this 👉 1-minute form to apply and book an intro call Thanks 🙂
    K 2
  • j

    Jérémy CROS

    11/10/2025, 3:59 PM
    Hi everyone 🙂 I'm looking to convert a callback from a 3rd party sdk we're using to a StateFlow and I can't for the life of me find something that works 😕 Code looks like that:
    Copy code
    class Provider {
    
        private val listener by lazy {
            object: 3rdPartyListener {
                // Bunch of callbacks
    
                // The one I actually care about
                override fun onError() {
                    // Spam errors when in errors, do nothing otherwise
                }
            }
        }
    }
    I've read about
    callbackFlow
    but I can't quite make it work. For the use case of a callback that spam error / do nothing, AI is suggesting using a
    debounce
    but I don't know, that seems weird... Any help / suggestions appreciated! 🙏
    t
    d
    l
    • 4
    • 5
  • l

    Lukasz Kalnik

    11/13/2025, 2:17 PM
    What is currently the most idiomatic way to check if a date (today) is between a range of dates, e.g. Nov 28th and Jan 6th (regardless of the year)?
    👍 1
    b
    j
    +3
    • 6
    • 26
  • j

    Joshua Hansen

    11/17/2025, 7:40 PM
    Very small annoyance but I still get a warning
    Assigned value is never read
    on
    aNumber += 1
    even with the suppressions. I personally consider this warning wrong but I'm sure people could argue about it. Is there anyway to suppress it? Also, why did the `Wrapped into a reference object to be modified when captured in a closure." statement go away?
    Copy code
    class Foo(val lambda: () -> Unit)
    
    @Suppress("UNUSED_VARIABLE", "UNUSED")
    fun test() {
        var aNumber = 0 // "Wrapped into a reference object..." doesn't show anymore
    
        val newFoo = Foo {
            val test = 1 + aNumber // Do something with current value
            aNumber += 1 // Change value to be used next time Foo.lambda() is called
        }
        // do something with newFoo here to use later like add it to a list, etc.
    }
    b
    d
    +2
    • 5
    • 7
  • p

    Pihentagy

    11/19/2025, 7:39 AM
    I have a project where incoming data is declared as a json schema. I'd like to generate dtos from the json schema on compile time. Can you recommend a library for that?
    s
    j
    • 3
    • 4
  • j

    Joshua Hansen

    11/19/2025, 7:25 PM
    Need some help with this one. I have a few objects which implement a generic interface and I have a list of those objects and I"m trying to work with a function. I can unsafe cast to get around this, but is there a method to achieving the same thing without this? Here is a simplified example:
    Copy code
    interface Test<T: Number> {
        val clazz: KClass<T> // Keep reference to the class so we can find the right one later
        fun foo(item: T)
    }
    
    // Int object:
    object A : Test<Int> {
        override val clazz = Int::class
        override fun foo(item: Int) {
            // do something
        }
    }
    
    // Double object
    object B : Test<Double> {
        override val clazz = Double::class
    
        override fun foo(item: Double) {
            // do something
        }
    }
    
    fun test() {
        // Working with a list of these objects
        val objs: List<Test<out Number>> = listOf(A, B)
        
        val myInt = 1
        
        // I'm certain find returns A, but due to forced out projection I get an error.
        val properObj = objs.find {
            it.clazz == myInt::class
        }
    
        properObj?.foo(myInt) // Receiver type 'Test<out Number>' contains out projection which prohibits the use of 'fun foo(item: T): Unit'.
    }
    c
    • 2
    • 1
  • m

    MrNiamh

    11/20/2025, 3:47 PM
    I have this simple example. Why does
    a
    compile fine, but
    b
    is a compilation error? I wouldn't expect
    a
    to compile but it does, but i'm also surprised it's not consistent between the two.
    Copy code
    data class ContactId(val value: UUID)
    
    fun main(){
        val contactId = ContactId(UUID.randomUUID())
        val uuid = UUID.randomUUID()
        val a = contactId == uuid
        val b = contactId.toString() == uuid
    }
    y
    k
    • 3
    • 3
  • s

    Slackbot

    11/24/2025, 5:59 PM
    This message was deleted.
    y
    k
    • 3
    • 7
  • s

    Stephan Schröder

    11/24/2025, 8:48 PM
    @ someone from Jetbrains, please clean up your Scaling Kotlin Adoption Across Your Organization article on your blog. I'm fairly certain the Developer record isn't supposed to have two properties called
    name
    , at least the Kotlin version doesn't.
    y
    k
    +3
    • 6
    • 6
  • e

    Edgar Avuzi

    11/29/2025, 3:10 AM
    Should this be reported as an issue of Intellij IDEA or Kotlin Compiler? The details are in the thread
    k
    • 2
    • 9
  • p

    Pihentagy

    11/30/2025, 11:59 AM
    Is the a full kotlin framework for a webapp (frontend+backend) exist? Can I host such apps somewhere for fully free? (just to test them, or for domestic use?) Like deno.dev for Deno (js).
    r
    j
    +2
    • 5
    • 20
  • g

    Gasan

    12/01/2025, 10:09 AM
    Hi all, Is there such a thing as union types in Kotlin? I looked in the Kotlin in Action book and haven't find such thing. That is, I would like to define my a property like this:
    class MyClass(val myProperty: Boolean|MyType)
    . The type of
    myProperty
    is a union of
    Boolean
    and
    MyType
    types. That is,
    myProperty
    value can be one of those types.
    c
    t
    c
    • 4
    • 8
  • s

    Slackbot

    12/01/2025, 4:38 PM
    This message was deleted.
    a
    n
    • 3
    • 2
  • s

    Slackbot

    12/02/2025, 1:49 PM
    This message was deleted.
    🎉 1
    r
    • 2
    • 1
  • p

    Pihentagy

    12/03/2025, 2:44 PM
    I'm asking advice for a csv deserialization library. I think the following things are important for me: • handles large csv files (outputs ~List~SequenceMyObject, does not store all rows in memory) • handles header row to address columns by "name" • target is JVM • support for null values
    r
    f
    +3
    • 6
    • 15
  • o

    okarm

    12/05/2025, 5:08 PM
    I'm getting this compiler error:
    Copy code
    e: java.lang.IllegalStateException: Unexpected member: <DANGLING MODIFIER: Top level declaration expected>
    	at org.jetbrains.kotlin.fir.backend.Fir2IrConverter.processMemberDeclaration(Fir2IrConverter.kt:551)
    	...
    when compiling a hefty chunk of generated code. How can I find which source file(s) is problematic? No Gradle logging option up to and including
    --debug
    makes the compiler print any more information.
    o
    • 2
    • 1
  • u

    ursus

    12/08/2025, 1:06 AM
    Is there a way to tell if my loops are vectorized?
    y
    d
    • 3
    • 8
  • k

    kqr

    12/08/2025, 7:32 AM
    Can someone explain to me, why this behaves as it behaves?
    y
    k
    • 3
    • 7