https://kotlinlang.org logo
Docs
Join the conversationJoin Slack
Channels
100daysofcode
100daysofkotlin
100daysofkotlin-2021
advent-of-code
aem
ai
alexa
algeria
algolialibraries
amsterdam
android
android-architecture
android-databinding
android-studio
androidgithubprojects
androidthings
androidx
androidx-xprocessing
anime
anko
announcements
apollo-kotlin
appintro
arabic
argentina
arkenv
arksemdevteam
armenia
arrow
arrow-contributors
arrow-meta
ass
atlanta
atm17
atrium
austin
australia
austria
awesome-kotlin
ballast
bangladesh
barcelona
bayarea
bazel
beepiz-libraries
belgium
berlin
big-data
books
boston
brazil
brikk
budapest
build
build-tools
bulgaria
bydgoszcz
cambodia
canada
carrat
carrat-dev
carrat-feed
chicago
chile
china
chucker
cincinnati-user-group
cli
clikt
cloudfoundry
cn
cobalt
code-coverage
codeforces
codemash-precompiler
codereview
codingame
codingconventions
coimbatore
collaborations
colombia
colorado
communities
competitive-programming
competitivecoding
compiler
compose
compose-android
compose-desktop
compose-hiring
compose-ios
compose-mp
compose-ui-showcase
compose-wear
compose-web
connect-audit-events
corda
cork
coroutines
couchbase
coursera
croatia
cryptography
cscenter-course-2016
cucumber-bdd
cyprus
czech
dagger
data2viz
databinding
datascience
dckotlin
debugging
decompose
decouple
denmark
deprecated
detekt
detekt-hint
dev-core
dfw
docs-revamped
dokka
domain-driven-design
doodle
dsl
dublin
dutch
eap
eclipse
ecuador
edinburgh
education
effective-kotlin
effectivekotlin
emacs
embedded-kotlin
estatik
event21-community-content
events
exposed
failgood
fb-internal-demo
feed
firebase
flow
fluid-libraries
forkhandles
forum
fosdem
fp-in-kotlin
framework-elide
freenode
french
fritz2
fuchsia
functional
funktionale
gamedev
ge-kotlin
general-advice
georgia
geospatial
german-lang
getting-started
github-workflows-kt
glance
godot-kotlin
google-io
gradle
graphic
graphkool
graphql
graphql-kotlin
graviton-browser
greece
grpc
gsoc
gui
hackathons
hacktoberfest
hamburg
hamkrest
helios
helsinki
hexagon
hibernate
hikari-cp
hire-me
hiring
hongkong
hoplite
http4k
hungary
hyderabad
image-processing
india
indonesia
inkremental
intellij
intellij-plugins
intellij-tricks
internships
introduce-yourself
io
ios
iran
israel
istanbulcoders
italian
jackson-kotlin
jadx
japanese
jasync-sql
java-to-kotlin-refactoring
javadevelopers
javafx
javalin
javascript
jdbi
jhipster-kotlin
jobsworldwide
jpa
jshdq
juul-libraries
jvm-ir-backend-feedback
jxadapter
k2-early-adopters
kaal
kafka
kakao
kalasim
kapt
karachi
karg
karlsruhe
kash_shell
kaskade
kbuild
kdbc
kgen-doc-tools
kgraphql
kinta
klaxon
klock
kloudformation
kmdc
kmm-español
kmongo
knbt
knote
koalaql
koans
kobalt
kobweb
kodein
kodex
kohesive
koin
koin-dev
komapper
kondor-json
kong
kontent
kontributors
korau
korean
korge
korim
korio
korlibs
korte
kotest
kotest-contributors
kotless
kotlick
kotlin-asia
kotlin-beam
kotlin-by-example
kotlin-csv
kotlin-data-storage
kotlin-foundation
kotlin-fuel
kotlin-in-action
kotlin-inject
kotlin-latam
kotlin-logging
kotlin-multiplatform-contest
kotlin-mumbai
kotlin-native
kotlin-pakistan
kotlin-plugin
kotlin-pune
kotlin-roadmap
kotlin-samples
kotlin-sap
kotlin-serbia
kotlin-spark
kotlin-szeged
kotlin-website
kotlinacademy
kotlinbot
kotlinconf
kotlindl
kotlinforbeginners
kotlingforbeginners
kotlinlondon
kotlinmad
kotlinprogrammers
kotlinsu
kotlintest
kotlintest-devs
kotlintlv
kotlinultimatechallenge
kotlinx-datetime
kotlinx-files
kotlinx-html
kotrix
kotson
kovenant
kprompt
kraph
krawler
kroto-plus
ksp
ktcc
ktfmt
ktlint
ktor
ktp
kubed
kug-leads
kug-torino
kvision
kweb
lambdaworld_cadiz
lanark
language-evolution
language-proposals
latvia
leakcanary
leedskotlinusergroup
lets-have-fun
libgdx
libkgd
library-development
linkeddata
lithuania
london
losangeles
lottie
love
lychee
macedonia
machinelearningbawas
madrid
malaysia
mathematics
meetkotlin
memes
meta
metro-detroit
mexico
miami
micronaut
minnesota
minutest
mirror
mockk
moko
moldova
monsterpuzzle
montreal
moonbean
morocco
motionlayout
mpapt
mu
multiplatform
mumbai
munich
mvikotlin
mvrx
myndocs-oauth2-server
naming
navigation-architecture-component
nepal
new-mexico
new-zealand
newname
nigeria
nodejs
norway
npm-publish
nyc
oceania
ohio-kotlin-users
oldenburg
oolong
opensource
orbit-mvi
osgi
otpisani
package-search
pakistan
panamá
pattern-matching
pbandk
pdx
peru
philippines
phoenix
pinoy
pocketgitclient
polish
popkorn
portugal
practical-functional-programming
proguard
prozis-android-backup
pyhsikal
python
python-contributors
quasar
random
re
react
reaktive
realm
realworldkotlin
reductor
reduks
redux
redux-kotlin
refactoring-to-kotlin
reflect
refreshversions
reports
result
rethink
revolver
rhein-main
rocksdb
romania
room
rpi-pico
rsocket
russian
russian_feed
russian-kotlinasfirst
rx
rxjava
san-diego
science
scotland
scrcast
scrimage
script
scripting
seattle
serialization
server
sg-user-group
singapore
skia-wasm-interop-temp
skrape-it
slovak
snake
sofl-user-group
southafrica
spacemacs
spain
spanish
speaking
spek
spin
splitties
spotify-mobius
spring
spring-security
squarelibraries
stackoverflow
stacks
stayhungrystayfoolish
stdlib
stlouis
strife-discord-lib
strikt
students
stuttgart
sudan
swagger-gradle-codegen
swarm
sweden
swing
swiss-user-group
switzerland
talking-kotlin
tallinn
tampa
teamcity
tegal
tempe
tensorflow
terminal
test
testing
testtestest
texas
tgbotapi
thailand
tornadofx
touchlab-tools
training
tricity-kotlin-user-group
trójmiasto
truth
tunisia
turkey
turkiye
twitter-feed
uae
udacityindia
uk
ukrainian
uniflow
unkonf
uruguay
utah
uuid
vancouver
vankotlin
vertx
videos
vienna
vietnam
vim
vkug
vuejs
web-mpp
webassembly
webrtc
wimix_sentry
wwdc
zircon
Powered by Linen
getting-started
  • d

    dany giguere

    10/15/2022, 8:07 PM
    Architectural question: I’d like to create an ecommerce where merchants could sign up and sell their products. So one website with multiple merchants. Now I’d like to be able to pay each merchant directly each time a product would be sold from the website (and take a cut directly as well). I’m thinking when a merchant sign up, they could enter their Mollie or Braintree (for instance) account number… Which payment platform would you people recommend ?
    y
    1 reply · 2 participants
  • s

    Slackbot

    10/16/2022, 4:56 AM
    This message was deleted.
    h
    v
    2 replies · 3 participants
  • e

    Erik

    10/16/2022, 2:54 PM
    Is it possible to call
    fun foo
    in this runnable example in a way that doesn't provide a value for the first parameter with a default value? The types of the first two parameters happen to be compatible, which is unfortunate (even though they're not the same!)
    y
    d
    9 replies · 3 participants
  • m

    maxmello

    10/17/2022, 1:10 PM
    fun <T: Any?> a(b: (value: T) -> Unit) {
        b(null)
    }
    why does this not work? Why does it say T is non-nullable, even though it uses
    Any?
    ? Can I make this work without changing the lambda param to
    value: T?
    ?
    e
    s
    3 replies · 3 participants
  • s

    Settingdust

    10/18/2022, 6:58 AM
    The
    b
    in
    a(c[0]!!(), b)
    will error with type mismatch. Expected
    CapturedType(out B*>)
    but
    B<*>
    . How to pass the
    b
    as param? https://pl.kotl.in/VVNMv8Zso Edited: add comment
    // KSerializer in my actual env
    open class A<T>
    
    // An external class from lib
    class B<T>
    
    // My serializer
    class C : A<B<Int>>()
    // A map to take correct serializer by arg
    val c: Map<Int, () -> A<out B<*>>> = mapOf(0 to { C() })
    
    // CompositeEncoder#encodeSerializableElement in my actual env
    fun <U, T : A<U>> a(a: T, b: U) {
    }
    
    // KSerializer#serialize(encoder: Encoder, value: B<*>) in my actual env
    fun b(b: B<*>) {
        a(c[0]!!(), b)
    }
    Error
    Type mismatch.
    Required:
    CapturedType(out B*>)
    Found:
    B<*>
  • y

    y

    10/18/2022, 8:39 AM
    coming from Rust: what is the equivalent of a
    Result
    in Kotlin, and is it idiomatic to use it? do failible functions in Kotlin generally return error types on failure, throw, or just return `null`/silently exit?
    s
    k
    +2
    20 replies · 5 participants
  • y

    y

    10/18/2022, 11:30 AM
    is there a more compact way to do this?
    var maybe_null = if (condition) { method_chain_that_may_return_null() } else { null }
    d
    n
    +3
    7 replies · 6 participants
  • l

    Loney Chou

    10/18/2022, 2:41 PM
    Why
    abstract
    can be
    inner
    , but
    sealed
    ,
    data
    not?
    g
    4 replies · 2 participants
  • r

    reactormonk

    10/18/2022, 3:56 PM
    Is there a
    retry
    or similar for `try`/`catch`?
    k
    s
    3 replies · 3 participants
  • l

    Luis Lopez Gonzalez

    10/19/2022, 6:46 AM
    Hi, I'm not sure I am using the right framework for my project. I want to make an app that sends customer's orders to me by mail, and allows for payment. Can I work on the front-end and back-end with IntellijJ IDEA, or sohould I be learning something else, like android studio for front-end? Thanks a lot
    v
    l
    3 replies · 3 participants
  • y

    y

    10/19/2022, 7:11 AM
    is there really no way to get Kotlin to auto-infer that in
    my_uint += 1
    the type of 1 is not
    Int
    ?
    s
    2 replies · 2 participants
  • a

    andylamax

    10/19/2022, 9:23 AM
    How is it that
    inline constructors
    are prohibited but there is an exception for the
    Array
    class implementation?
    y
    2 replies · 2 participants
  • r

    Rohit Lagu

    10/19/2022, 8:18 PM
    is there any way to check maps has all values null? val m = mapOf(“s” to null, “a” to null) Not working >> println(m.values.isNullOrEmpty()) working >> println(m.values.all{it == null}) better way >>?
    c
    1 reply · 2 participants
  • n

    Norbi

    10/20/2022, 8:02 AM
    Is it possible to get an insight into Kotlin development strategy? I really don't understand some of the decisions regarding the development and advancement of Kotlin. Just an example: in my opinion Kotlin multiplatform is one of the most important Kotlin feature, and yet it is full of blocker bugs and incomplete core features (eg. Gradle composite build). In the meantime, the team spends a lot of time developing minor features, like the new range operator. Value classes: it is a great feature and I personally like and use them a lot, but are they really worth the enormous amount of work put into them? The target platforms should and will optimize them in compile/runtime anyway sooner or later. I don't want to sound offensive, I just really want to understand the priorities, and understand why it is not possible to do a feature freeze until the current functionality has much less bugs...
    s
    m
    +1
    4 replies · 4 participants
  • a

    Ayfri

    10/20/2022, 12:42 PM
    Hi, is there an idiomatic way to attribute a value to a variable if this variable is null ? Other than a
    if
    s
    j
    +3
    10 replies · 6 participants
  • v

    Viktor Sirotin

    10/20/2022, 8:24 PM
    It seems there is not in Kotlin infix function without parameters. I mean, we can not in some way implement something like: fun main() { println(1 m) } infix fun Number.m() = Meter(this.toDouble()) class Meter(val value: Double) Or exist some trick?
    j
    r
    3 replies · 3 participants
  • m

    Martin Kolesar

    10/21/2022, 1:21 PM
    Hi,How it is possible to return array of items if there is when inside, how should I modify the else bracnh to get it working fun printAll(type: Int): Array<String> { // 1 return arrayOf( when(type) { 1 -> "one" 2 -> "two" else -> { "three","four" } } ) }
    j
    5 replies · 2 participants
  • t

    Tech

    10/21/2022, 7:21 PM
    Hey I was wondering how I enable Kotlin 1.7.20 features? I set my JVM version to 1.7.20 in the gradle build
    kotlin("jvm") version "1.7.20"
    Trying to use data objects but run into this error
    The feature "data objects" is only available since language version 1.8
    , thanks in advance.
    e
    s
    3 replies · 3 participants
  • j

    Joshua Hansen

    10/21/2022, 10:58 PM
    I have
    foo: String
    and
    bar: List<String>
    . What's a clever way to return true if
    foo
    starts with (or I guess
    contains
    works too) at least one string in
    bar
    ?
    k
    j
    4 replies · 3 participants
  • h

    hfhbd

    10/21/2022, 11:34 PM
    How do you use delegation and a where clause?
    interface F
    class B<T>(t: T) : F by t where T : F
    1 reply · 1 participant
  • d

    David Hu

    10/22/2022, 4:01 AM
    why does the following code snippet
    "foo" > "bar"
    magically works in Kotlin REPL and returns a boolean instead of throwing an error or exception? how is it even possible to "compare" strings this way when the same code in Java does not work at all?!
    k
    2 replies · 2 participants
  • v

    v79

    10/22/2022, 7:03 AM
    When is a nullable value not nullable? Somewhat confused by these two messages in Android Studio - in the middle of a
    ?.let { }
    block, no less. The value from the repository is hypothetically null, but I thought the let block would have handled that.
    c
    e
    3 replies · 3 participants
  • l

    Loney Chou

    10/22/2022, 2:36 PM
    How can I pass value class parameter from Java? IDEA suggests me using the underlying type but it's just a compilation error.
    e
    m
    9 replies · 3 participants
  • m

    Mikael Ståldal

    10/24/2022, 7:50 AM
    I have a function like this at top-level of a Kotlin file:
    package mypackage
    
    fun main(args: Array<String>) {
        // ...
    }
    Usually used as program entrypoint in JVM. However, when I try to call it from another Kotlin module:
    import mypackage.main
    
    class MyClass {
        fun myMethod() {
            main(arrayOf("foo", "bar"))
        }
    }
    I get this strange error:
    Kotlin: Overload resolution ambiguity: 
    public fun main(args: Array<String>): Unit defined in mypackage
    public fun main(args: Array<String>): Unit defined in mypackage
    j
    10 replies · 2 participants
  • y

    Yogeshvu

    10/24/2022, 3:18 PM
    any good libraries for generating json from a json-schema?
    h
    c
    5 replies · 3 participants
  • n

    Nat Strangerweather

    10/25/2022, 2:27 PM
    Could you please help me work this out? I have three buttons and when I select one, I want the other two to be disabled until I unselect it. I can't figure out out to put that into code. I thought that this would work (at least for the first button):
    if (option.id == 0) {
                    for (o in listOfOptions) {
                        when (o.id) {
                            1 -> enabled = false
                            2 -> enabled = false
                        }
                    }
                }
    But all my 3 buttons are disabled when I do this... 🤔
    s
    p
    +1
    10 replies · 4 participants
  • m

    Michael de Kaste

    10/25/2022, 4:16 PM
    isn't this decidable somehow?
    sealed interface Foo
    sealed interface Bar
    sealed interface Thing {
        object ONE : Thing, Foo
        object TWO : Thing, Bar
    }
    
    fun main(){
        val thing: Thing = Thing.ONE
        if(thing is Foo && thing is Bar){
            // This can´t happen
        }
    }
    c
    j
    5 replies · 3 participants
  • i

    Ink

    10/26/2022, 8:44 AM
    I get string:
    name: tom, weight: 50, age: 21
    How I can get value
    name
    ,
    weight
    ,
    age
    ?
    a
    g
    +3
    16 replies · 6 participants
  • n

    Nat Strangerweather

    10/26/2022, 4:57 PM
    Hi, I read that if I want two functions to run consecutively, they have to be suspend functions. So I turned
    function1 ()
    and
    function2 ()
    into suspend functions, and set them up like this:
    val scope = rememberCoroutineScope()
    
        ElevatedButton(
            onClick = {
                scope.launch {
                    function1 ()
                    function2 ()
                }
            },
    The problem is that I need for function1 to be completed before function2 can start. So if I put a 1 second delay between the two, my app works as expected, but if I don't it seems function2 does not wait for function1 to complete before it starts. Is there a way to get f1 to finish before f2 starts without adding a delay in between the two?
    c
    6 replies · 2 participants
  • j

    Joseph S

    10/26/2022, 7:23 PM
    Hi I read the docs that I need to have Cocoapods installed for iOS if I want more extended features while developing for iOS. I managed to install it after the IDE told me I was missing them. How can I make it recognize the installed package now? Edit: Nvm I think I got it
Powered by Linen
Title
j

Joseph S

10/26/2022, 7:23 PM
Hi I read the docs that I need to have Cocoapods installed for iOS if I want more extended features while developing for iOS. I managed to install it after the IDE told me I was missing them. How can I make it recognize the installed package now? Edit: Nvm I think I got it
View count: 2