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

    Daniele B

    06/02/2021, 2:05 PM
    I would like to remove elements from a collection, based on a condition. For a list, we can use:
    myList.removeAll { it.myField != myFieldValue }
    But for a map, there doesn’t seem to be
    removeAll
    :
    myMap.removeAll { it.key != myKeyValue }    <--- removeAll doesn't exist
    what should I use instead?
    l
    i
    e
    • 4
    • 7
  • z

    Zun

    06/06/2021, 1:41 PM
    Not new to Kotlin but new to Flow. Is there a way to rewrite the following code to make it shorter, or do I need to resort to writing my own extension? I need to emit null when the list is empty
    k
    • 2
    • 5
  • j

    Justin Yue

    06/08/2021, 2:20 AM
    I was told that there was a place where I can see the implementation of functions in Kotlin's standard library. I was wondering if that was a place in the Kotlin docs, or do I somehow inspect the code in IntelliJ to get the implementation?
    d
    c
    +3
    • 6
    • 11
  • c

    CLOVIS

    06/08/2021, 8:51 AM
    I have a gradle project with Kotlin 1.5.10. IDEA doesn't find
    @JvmInline
    , and says I should add
    kotlin-stdlib:1.4.31
    to the class path. Is there something hidden somewhere in the settings?
    g
    • 2
    • 2
  • r

    rtsketo

    06/09/2021, 12:56 PM
    Is there anyway in Kotlin to have two constructors in class with both having lists as an argument but with different types in them? For example:
    constructor(aList : List<A>)  /* Main constructor */
    constructor(bList : List<B>) : this (bList.toListA())
    I get the following:
    Platform declaration clash: The following declarations have the same JVM signature ((Ljava/util/List;)V):
    How do I distinguish between them?
    m
    c
    +3
    • 6
    • 10
  • t

    Tarun Chawla

    06/10/2021, 6:57 AM
    how to set the kotlin version in gradle file? This is my build.gradle.kts:
    import org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpack
    
    plugins {
      kotlin("multiplatform") version "1.5.10"
      kotlin("plugin.serialization") version "1.5.10"
      application
    }
    
    group = "tech.tarunchawla"
    version = "0.0.1"
    
    repositories {
      jcenter()
      mavenCentral()
      maven { url = uri("<https://dl.bintray.com/kotlin/kotlin-js-wrappers>") }
      maven { url = uri("<https://dl.bintray.com/kotlin/kotlinx>") }
      maven { url = uri("<https://dl.bintray.com/kotlin/ktor>") }
      maven("<https://dl.bintray.com/konform-kt/konform>")
    }
    
    kotlin {
      jvm {
        compilations.all {
          kotlinOptions.jvmTarget = "1.8"
        }
        testRuns["test"].executionTask.configure {
          useJUnit()
        }
        withJava()
      }
      js(LEGACY) {
        browser {
          binaries.executable()
          webpackTask {
            cssSupport.enabled = true
          }
          runTask {
            cssSupport.enabled = true
          }
          testTask {
            useKarma {
              useChromeHeadless()
              webpackConfig.cssSupport.enabled = true
            }
          }
        }
      }
      sourceSets {
        val commonMain by getting {}
        val commonTest by getting {
          dependencies {
            implementation(kotlin("test-common"))
            implementation(kotlin("test-annotations-common"))
          }
        }
        val jvmMain by getting {
          dependencies {
            implementation("io.ktor:ktor-server-netty:1.6.0")
            implementation("io.ktor:ktor-html-builder:1.6.0")
            implementation("org.jetbrains.kotlinx:kotlinx-html-jvm:0.7.2")
            implementation("io.ktor:ktor-gson:1.6.0")
            implementation("io.ktor:ktor-auth:1.6.0")
            implementation("io.ktor:ktor-auth-jwt:1.6.0")
            implementation("io.ktor:ktor-serialization:1.6.0")
            implementation("org.postgresql:postgresql:42.2.20")
            implementation("org.jetbrains.exposed:exposed-core:0.31.1")
            implementation("org.jetbrains.exposed:exposed-jdbc:0.31.1")
            implementation("org.jetbrains.exposed:exposed-java-time:0.31.1")
            implementation("com.auth0:java-jwt:3.10.3")
          }
        }
        val jvmTest by getting {
          dependencies {
            implementation(kotlin("test-junit"))
            implementation("org.xerial:sqlite-jdbc:3.34.0")
          }
        }
        val jsMain by getting {
          dependencies {
            implementation("io.ktor:ktor-client-js:1.6.0")
            implementation("io.ktor:ktor-client-serialization:1.6.0")
            implementation("org.jetbrains.kotlin-wrappers:kotlin-react:17.0.2-pre.206-kotlin-1.5.10")
            implementation("org.jetbrains.kotlin-wrappers:kotlin-react-dom:17.0.2-pre.206-kotlin-1.5.10")
            implementation(npm("react", "17.0.2"))
            implementation(npm("react-dom", "17.0.2"))
            implementation("org.jetbrains.kotlin-wrappers:kotlin-styled:5.3.0-pre.206-kotlin-1.5.10")
            implementation(npm("styled-components", "~5.3.0"))
            implementation("org.jetbrains.kotlin-wrappers:kotlin-react-router-dom:5.2.0-pre.206-kotlin-1.5.10")
            implementation("org.jetbrains.kotlin-wrappers:kotlin-redux:4.0.5-pre.206-kotlin-1.5.10")
            implementation("org.jetbrains.kotlin-wrappers:kotlin-react-redux:7.2.3-pre.206-kotlin-1.5.10")
            implementation("org.jetbrains.kotlinx:kotlinx-datetime:0.2.1")
            implementation("io.konform:konform-js:0.2.0")
          }
        }
        val jsTest by getting {
          dependencies {
            implementation(kotlin("test-js"))
          }
        }
      }
    }
    
    application {
      mainClass.set("MainKt")
    }
    
    tasks.withType<Jar> {
      manifest {
        attributes["Main-Class"] = "MainKt"
      }
      from(sourceSets.main.get().output)
    
      dependsOn(configurations.runtimeClasspath)
      from({
        configurations.runtimeClasspath.get().filter { it.name.endsWith("jar") }.map { zipTree(it) }
      })
    }
    
    tasks.getByName<KotlinWebpack>("jsBrowserProductionWebpack") {
      outputFileName = "output.js"
    }
    
    tasks.getByName<Jar>("jvmJar") {
      dependsOn(tasks.getByName("jsBrowserProductionWebpack"))
      val jsBrowserProductionWebpack = tasks.getByName<KotlinWebpack>("jsBrowserProductionWebpack")
      from(File(jsBrowserProductionWebpack.destinationDirectory, jsBrowserProductionWebpack.outputFileName))
    }
    
    tasks.getByName<JavaExec>("run") {
      dependsOn(tasks.getByName<Jar>("jvmJar"))
      classpath(tasks.getByName<Jar>("jvmJar"))
    }
    s
    • 2
    • 2
  • b

    Ben Nash

    06/10/2021, 10:05 PM
    Cross-posting from #opensource. I'm new and hopefully doing this right.
    👍 1
    e
    a
    • 3
    • 4
  • m

    Morgan

    06/12/2021, 12:49 PM
    Hi everyone. I think this channel is the right place to ask but let me know if I should move the conversation elsewhere... Basically I am interested in picking up Android development but know nothing about Kotlin. I programmed in Java a long time ago (Java 5/6 so a long time ago!) however can't remember anything from back then. I've also done C++ (98 nothing modern) for Windows desktop application development (MFC 😩) back in the early 2000s (around when .NET came out). Again I don't remember language specifics just general programming concepts. I am wondering what is the best approach for me to go about teaching myself Kotlin and refreshing DS&A and some programming related maths I have long forgotten?
    k
    k
    +2
    • 5
    • 15
  • t

    thhh

    06/15/2021, 1:32 PM
    how to create a blocking call without using thread and runblocking? Usecase is I want to use something instead of
    thread { ... }
    in this code: https://pastebin.com/d9xvi3ay When using
    thread
    Timber Logging library incorrectly assigns Tag. Like even when using Timber.d from Acitivity or other class, it will show Tag of Application class (where Timber is initialized)
    d
    • 2
    • 1
  • d

    Daniele B

    06/16/2021, 9:16 AM
    I would like to express a suspend function as a callback:
    suspend fun getMyObject() : MyObject {
       ...
       return myObject
    }
    
    val myApp = myCallback { myObject ->
       /* code using myObject */
    }
    how should I write the function 
    myCallback
    ?
    w
    s
    c
    • 4
    • 7
  • s

    Scott Wilson-Billing

    06/16/2021, 4:44 PM
    Hi 👋 looking for some help please, i'm new to Kotlin and React and trying to use an external JS lib https://github.com/tailwindlabs/headlessui
    c
    • 2
    • 1
  • s

    Scott Wilson-Billing

    06/16/2021, 4:48 PM
    any help much appreciated. thanks
    d
    • 2
    • 2
  • j

    Jack W

    06/16/2021, 5:01 PM
    Hey everyone! This is my first time using Slack and I am also a beginner with Kotlin, so let me know if this question should go somewhere else. My question is: is Kotlin/Native for iOS “safe” to get started with given the memory management redesign? I am confused about whether or not code will have to be rewritten for Kotlin Multiplatform Libraries/modules once the iOS memory management redesign is released. Thanks!
    👋 1
    s
    • 2
    • 2
  • t

    trofman

    06/18/2021, 6:28 AM
    hi! can i declare something like
    some.thing.like
    as
    one
    without doing
    val one = some.thing.like
    ?
    m
    b
    • 3
    • 3
  • s

    Slackbot

    06/21/2021, 9:22 AM
    This message was deleted.
    g
    • 2
    • 1
  • a

    alexeenkoff

    06/21/2021, 9:54 AM
    Hello, everyone! Question about work around exceptions in KMM Is there any good articles about best practices to work with NSError? is
    localizedDescription
    - best way to differ exceptions?
    j
    • 2
    • 2
  • h

    hoang

    06/23/2021, 7:50 AM
    Hi, why is spread operator not work with split(): https://pl.kotl.in/5xrsPYB2c
    a
    e
    • 3
    • 3
  • p

    Peter

    06/23/2021, 1:42 PM
    Is it somehow possible to create an operator extension function is the underlying Java class already defines the operator as a regular function (minus in this example):
    operator fun SomeClass.minus(b: SomeClass) = minus(b)
    d
    • 2
    • 2
  • m

    Manuel Pérez Alcolea

    06/25/2021, 3:46 AM
    when I declare a class
    MyClass
    and an interface
    MyInterface
    and have several classes extending and implementing them, Kotlin infers both the class and the interface in generic types. For example
    val list = listOf(ImplemA(), implemB())
    contains objects that are
    MyClass
    and comply with
    MyInterface
    . IDEA describes the bound as
    <{MyClass & MyInterface}>
    in that case. Can I specify a type like that explicitly, without creating a new class? What's the catch?
    d
    d
    • 3
    • 5
  • m

    Matias Reparaz

    06/25/2021, 12:53 PM
    Hello everyone, I was playing around with val functions and I ran into this problem ... could someone help me understand why the e option doesn’t work (which would seem the most reasonable) and why all the above works? https://pl.kotl.in/YdmU2qEUy
    d
    e
    • 3
    • 9
  • s

    Sanendak

    06/26/2021, 4:52 PM
    Hello everyone! How to use property from object? Code in 🧵
    👋 1
    a
    c
    +2
    • 5
    • 10
  • k

    kierans777

    06/29/2021, 4:41 AM
    Is there a way to have a function return a function with a generic type in Kotlin? I want to do
    fun doSomething(): (Class<T>) -> T {}
    However because lambda expressions can't have generic types, this doesn't compile for me.
    e
    r
    • 3
    • 10
  • v

    Vitaliy Zarubin

    06/30/2021, 9:30 AM
    What this "some overhead" is? So, the sequences let you avoid building results of intermediate steps, therefore improving the performance of the whole collection processing chain. However, the lazy nature of sequences adds some overhead which may be significant when processing smaller collections or doing simpler computations. Hence, you should consider both Sequence and Iterable and decide which one is better for your case. https://kotlinlang.org/docs/sequences.html#construct
    m
    • 2
    • 1
  • o

    oday

    07/01/2021, 5:00 PM
    something really weird is happening here https://paste.ofcode.org/uf6LdvHyQQfTpNYmVKR2nE
    k
    r
    • 3
    • 46
  • t

    tipsy

    07/02/2021, 10:47 AM
    is there any built-in util method from converting an outputstream to an inputstream?
    s
    • 2
    • 3
  • d

    DMITRY.

    07/04/2021, 2:41 PM
    I have a spring boot application and its memory usage is constantly growing. How to start looking what might be the cause of this?
    s
    j
    c
    • 4
    • 12
  • l

    Lqncer

    07/04/2021, 6:08 PM
    I'm pretty much a brand new programmer. I've been sucked into this loophole of not being able to decide what language to use. I like the idea of Kotlin, but the people I've spoke with have told me that it is not beginner-friendly and that there are too many quirks in the language for it to be my first language/you need to know Java beforehand, and that I'd be better off with Python/JavaScript. Also, that the community isn't large enough to have the answers to my questions. Could anybody clarify these rumors and help me get out of this awful loophole! Thanks! 🙂
    o
    s
    +2
    • 5
    • 12
  • o

    oday

    07/04/2021, 7:07 PM
    does this
    typealias Visitor<T> = (TreeNode<T>) -> Unit
    mean, “any function that takes TreeNode<T> and return Unit can now be referred to as
    Visitor<T>
    ? so instead of writing
    fun search(printResult: (TreeNode<T>) -> Unit)
    I write
    fun search(visit: Visitor<T>)
    d
    • 2
    • 2
  • t

    tipsy

    07/05/2021, 8:22 PM
    i'm trying to offer two methods with similar signatures:
    inline fun <reified T : Any> queryParam(key: String) = ...
    fun queryParam(key: String) = ...
    in kotlin this works fine, but both mockk and mockito get confused, it's random which one of the methods get picked. is there any way of dealing with this?
    n
    • 2
    • 5
  • o

    oday

    07/06/2021, 9:04 AM
    what’s the difference between
    interface Stack<T : Any>
    and
    interface Stack<T>
    ?
    T
    already means literally anything
    m
    • 2
    • 7
Powered by Linen
Title
o

oday

07/06/2021, 9:04 AM
what’s the difference between
interface Stack<T : Any>
and
interface Stack<T>
?
T
already means literally anything
m

Matteo Mirk

07/06/2021, 9:08 AM
by default T implies
T : Any?
so includes nullable types. Your first declaration excludes nullable types from the domain.
o

oday

07/06/2021, 9:10 AM
I see, nice ok
true, if you go to implement this interface with a class that has type just
T
, feeding that
T
back to Stack<T> will complain
m

Matteo Mirk

07/06/2021, 9:20 AM
not sure I understand what you mean, sorry 😕
o

oday

07/06/2021, 9:20 AM
means I tried it, it’s as you said 👍🏻
m

Matteo Mirk

07/06/2021, 9:23 AM
okay good! So the compiler prevents you from declaring a
Stack<Int?>
if you used the first definition, right?
o

oday

07/06/2021, 9:25 AM
correct
👌 2
View count: 1