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
random
  • f

    Francis Mariano

    09/15/2022, 7:10 PM
    Anyone here already done any blockchain (BSC) related stuffs ???
  • g

    Gavin Ray

    09/16/2022, 9:30 PM
    @sam Forgive the ping here, but there's no channel for Tribune or GH Discussions enabled on it I have a question -- I have value classes which get deserialized from primitive values like
    String
    using Jackson Currently, these are modeled like this:
    data class ColumnName
    @JsonCreator(mode = JsonCreator.Mode.DELEGATING)
    constructor(@JsonValue val value: String) {
        init {
            require(value.isNotBlank()) { "Column name cannot be blank" }
            require(value.all { it.isLetterOrDigit() || it == '_' }) { "Column name must be alphanumeric" }
        }
    }
    Would the best practice using your library be to just replace the
    require()
    with
    require(parse(value))
    ?
    s
    • 2
    • 3
  • y

    Youssef Shoaib [MOD]

    09/16/2022, 11:20 PM
    I can imagine that using ketchup on your hair probably isn't the best of ideas
    b
    • 2
    • 1
  • l

    Laurent Laborde

    09/17/2022, 10:14 AM
    The more i learn about kotlin, the more i believe it’s the best general purpose language. (Still not my favorite though, Fortran forever <3)
  • a

    Alex Styl

    09/17/2022, 12:48 PM
    hi folks. I am trying to build a small app to send files from my android to my mac wirelessly. I found out about bonjour that helps discover nearby devices and I was able to detect my MBP from my android. Any hints towards what APIs (desktop + android) I need to use in order to do the actual sharing? I first spotted WiFi-Direct but it seems like Apple doesn’t support it. Anyone has experience with such use case?
  • l

    Laurent Laborde

    09/18/2022, 8:01 AM
    any serverless/embedded (like sqlite) database recommendation ? i want to store some configuration data and “states” (think of it as a load/save in a game, except that i’m not making a game but a simulation). Since i’m doing all this stuff for self-teaching purpose, i might as well take something i don’t know. (i’m a database administrator, the only “serverless” dbms i know is sqlite). it’s not specifically kotlin related so i’m just posting it here. (and it’s not that important either since i could make sqlite fit the need). i’ve heard about objectbox.
    g
    b
    +2
    • 5
    • 11
  • p

    Philipp Mayer

    09/19/2022, 9:08 AM
    Hi everyone, I’m currently trying to merge three method calls that alls return a specific subtype of a sealed interface into one call. The idea is to supply the expected result from the outside, so I don’t have to check the result type anymore. Here’s an example:
    sealed interface SomeResult {
        data class A(val s: String): SomeResult
        data class B(val i: Int): SomeResult
        data class C(val b: Boolean): SomeResult
    }
    
    class SomeService {
        fun request1(): SomeResult.A = TODO()
        fun request2(): SomeResult.B = TODO()
        fun request3(): SomeResult.C = TODO()
    }
    
    class MyCurrentImpl(val someService: SomeService) {
        fun blabla11(): SomeResult.A {
            //same setup, just calls request1()
            someService.request1()
            TODO()
        }
        fun blabla22(): SomeResult.B {
            //same setup, just calls request2()
            someService.request2()
            TODO()
        }
        fun blabla33(): SomeResult.C {
            //same setup, just calls request3()
            someService.request3()
            TODO()
        }
        
        //TODO: 
        // Merge all the setup & call into one method.
        // Additionally, supply result type from the outside, 
        // so I don't have 3 when statements.
        inline fun <reified T: SomeResult> getPaymentOptions(): T = 
            when {
                //Error: Type parameter 'T' is not an expression
                //Error: Required: T Found: SomeResult.B
                T is SomeResult.A -> someService.request1()
                T is SomeResult.B -> someService.request2()
                T is SomeResult.C -> someService.request3()
            }
        }
    }
    The important bit (in my imagination) is, that
    T
    always has to be of type
    SomeResult
    , so it’s sealed. Hence I was hoping to somehow iterate over it.. 🤔 Any ideas? Thanks in advance!
    y
    • 2
    • 2
  • g

    groostav

    09/20/2022, 8:21 PM
    I just had one of our API users tell me that
    waiting for the connection takes a long time so I use a hard-coded
    sleep(5.seconds)
    in my code
    for users of #coroutines, do you guys find junior developers (or any developers) doing this kind of thing for asyncs? Rather than synchronize properly (maybe because that involves bubbling some future up a call stack or converting a future to a channel for more granular synchronization), they simply insert hard-coded wait statements? I'm kinda mortified. I really don't want to have to explaining concurrency to somebody who works for another company. I want to just say "you're an idiot, call the WaitFor method, and dont ever use this strategy again." Now I have to find a way to put that into an email nicely...
    l
    t
    +2
    • 5
    • 5
  • j

    John Aoussou

    09/26/2022, 12:17 PM
    Is there a Kotlin equivalent of numpy's expand_dims?
    s
    • 2
    • 1
  • j

    Juliane Lehmann

    09/27/2022, 12:50 PM
    You could draw two arcs on top of each other.
    n
    r
    • 3
    • 4
  • c

    christophsturm

    09/29/2022, 11:32 AM
    is there something like mdoc for kotlin? https://scalameta.org/mdoc/ it looks very useful.
    c
    • 2
    • 4
  • u

    Ugai

    09/30/2022, 7:48 AM
    in 1.7.10 with jdk 17.0.3
    fun main() {
        val v1 : Int = 0
        class t {
            val v1: Int =1
            fun f0() : Int {
                return v1
            }
        }
        
        val t0 = t()
        println(t0.f0())
    }
    I got 0. Is this correct? I suppose it to be 1.
    s
    • 2
    • 2
  • n

    nuhkoca

    10/01/2022, 12:40 PM
    Code for drawing the triangle
    val triangle = Path().apply {
        moveTo(x = x, y = y - indicatorHalfSizeInPx)
        lineTo(x = x - indicatorHalfSizeInPx, y = y + indicatorHalfSizeInPx)
        lineTo(x = x + indicatorHalfSizeInPx, y = y + indicatorHalfSizeInPx)
        lineTo(x = x, y = y - indicatorHalfSizeInPx)
        close()
    }
  • e

    evanchooly

    10/04/2022, 3:30 PM
    i'm running a poll on coroutines vs reactive in kotlin APIs. Your input would be greatly appreciated. https://twitter.com/evanchooly/status/1577307714367152129
  • e

    elect

    10/06/2022, 9:21 AM
    kdoc method link cant resolve methods with same name but different signature? What a bummer..
    s
    • 2
    • 2
  • s

    Sam

    10/07/2022, 1:18 PM
    If I have a value
    t: T
    , why does
    t::class
    return
    KClass<out T>
    and not
    KClass<T>
    ?
    • 1
    • 4
  • d

    dewildte

    10/08/2022, 4:49 PM
    What keyboard layout do you use? 1️⃣ QWERTY 2️⃣ Dvorak 3️⃣ Colemack 4️⃣ Other
    j
    b
    l
    • 4
    • 4
  • e

    elect

    10/08/2022, 7:16 PM
    https://twitter.com/Ajediday/status/1578337592352948230
    r
    • 2
    • 2
  • l

    louiscad

    10/10/2022, 3:01 PM
    KMM Beta, which seems to be the focus of that upcoming online event was blocked by the new memory manager become good enough to be the default, and so it became in 1.7.20.
    x
    d
    • 3
    • 2
  • m

    mcpiroman

    10/13/2022, 5:36 PM
    Now that's an infinite loop and/or a half
  • o

    oday

    10/14/2022, 10:43 AM
    where can we discuss Fleet stuff? it makes sense to have a channel here, where else would you if not here? plus it’s written in Kotlin; thanks
    l
    • 2
    • 2
  • e

    Ellen Spertus

    10/15/2022, 4:40 AM
    I sent an email to my students today telling them not to include
    !!
    on assignments, or they would lose points (and their code would potentially throw NPEs). A few hours later, a fellow professor (not of my course) posted to an internal Team:
    Are other people getting anxious questions about details in assignments? "Professor, I put two exclamation points after 'Hello world!', will you take off points for that?"
    I let him know that, indeed, I would take points off for having two exclamation points in an assignment.
    r
    c
    +4
    • 7
    • 11
  • d

    Davide Giuseppe Farella

    10/15/2022, 4:19 PM
    Will it ever be possible to call private members from inline functions?
    l
    c
    • 3
    • 3
  • h

    hhariri

    10/16/2022, 11:16 AM
    Quite a few have pinged me about this, so sharing here - we won't be creating a Fleet channel on this Slack for two reasons 1. This is a Kotlin Slack and while Fleet and Kotlin are from the same company, it's not right to mix things. 2. Fleet already has its own Slack which was used during the private preview. You're welcome to now join. If you'd like to, use the following form. https://surveys.jetbrains.com/s3/fleet-slack-sign-up
  • y

    Youssef Shoaib [MOD]

    10/16/2022, 7:07 PM
    How long does Dokka take to generate HTML for you guys? on my machine it's taking upwards of 5-10 minutes, and I literally have no functions in a multiplatform module that it's running on. Am I misconfiguring it?
    b
    n
    +2
    • 5
    • 6
  • d

    Davide Giuseppe Farella

    10/18/2022, 12:18 PM
    Hello, is there a Fleet channel? I didn’t find any 😞
    k
    • 2
    • 2
  • a

    ayodele

    10/19/2022, 9:35 AM
    Hello, does JetBrains gateway support android development on Intellij Idea?
    b
    • 2
    • 2
  • a

    andylamax

    10/23/2022, 9:12 PM
    Anyone know of any unofficial/hacky way, I can develop ios/macOs apps on a linux machine using KMP??
    b
    d
    +5
    • 8
    • 24
  • m

    mattinger

    10/24/2022, 9:35 PM
    so i’m creating a sealed interface but for some reason the exhaustive when clause is kicking in for abstract implementations:
    sealed interface A {
        abstract class AbstractA: A
        class B: AbstractA()
        class C: AbstractA()
    }
    
    fun x(a: A) {
        when (a) {
            is A.B -> { }
            is A.C -> { }
        }
    }
    Has anyone else noticed this before? I get a compile error on the when saying i need to add an implementation for AbstractA, even though it can never be anything but B or C since those are the only concrete implementations.
    e
    a
    • 3
    • 5
  • a

    ayodele

    10/27/2022, 8:15 AM
    Since I've been coding in Kotlin my usage of classes has highly reduced (except on Android). It's mostly some set of functions in a kt file. Is that good practice??
    y
    p
    • 3
    • 3
Powered by Linen
Title
a

ayodele

10/27/2022, 8:15 AM
Since I've been coding in Kotlin my usage of classes has highly reduced (except on Android). It's mostly some set of functions in a kt file. Is that good practice??
y

Youssef Shoaib [MOD]

10/27/2022, 9:46 AM
Depends on the complexity of your applications. Personally I found myself using a lot more `data class`es and a lot less normal classes just because data classes make sense in a lot of contexts.
a

ayodele

10/27/2022, 10:11 AM
Yeah, same thing here. I use data classes alot
p

Pablichjenkov

10/28/2022, 1:11 AM
I believe is a good thing. You are becoming more of a functional programmer. The philosophy behind a class was encapsulating a mutable state and provide methods/actions to mutate that state. That philosophy brings pain with it, modern practices point out that is better modeling your program as a set of functions that process/produce immutable state, less prone to errors and bugs.
View count: 1