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
  • s

    statmark56

    09/01/2022, 2:48 PM
    Was expecting:
    sealed class Element<T>(val value: T)
    
    object Test : Element(10) // expecting compiler somehow able to refer the implicit integer 10 value to resolve T
    But actually need to explicitly declare the argument type to satisfy the compiler:
    object Test : Element<Int>(10)
    Any reason why? Thank you.
    e
    • 2
    • 1
  • n

    Nick

    09/01/2022, 5:46 PM
    Say my app version is using Kotlin 1.6.21, and I include two other dependencies that are using Kotlin
    1.7.0
    and
    1.4.32
    . Is there any possibility that there could be some sort of conflict since the versions are different? What about a similar situation with something like Jetpack Compose or Koin?
    a
    a
    e
    • 4
    • 6
  • r

    Rob Elliot

    09/02/2022, 8:18 AM
    Anyone ever needed to make a class with an
    init
    block entirely lazy? Example in the thread. (I suspect I'm going to get "smells of a poor design" and that may well be right but my imagination is failing me on how to fix it at the moment...)
    • 1
    • 5
  • o

    oday

    09/02/2022, 9:23 AM
    sealed interface EmptyResult {
        object Success : EmptyResult
        class Failure(val error: Throwable) : EmptyResult
    }
    
    sealed class DeleteResult : EmptyResult
    sealed class SetResult : EmptyResult
    Why can’t I access SetResult.Success or DeleteResult.Success?
    y
    k
    s
    • 4
    • 13
  • n

    NelsonC

    09/02/2022, 12:47 PM
    Hello. I am trying to make a simple game based on choices. Do I have to make a new empty activity every time I want a new screen to appear when you lcikc a choice or is there any simpler way? Thanks!
    c
    • 2
    • 4
  • y

    Yogeshvu

    09/02/2022, 3:52 PM
    Looking for suggestions on Coroutines book for server side applications (Non-Android platform). Any book which you would recommend here. thanks..
    j
    m
    • 3
    • 3
  • r

    rednifre

    09/02/2022, 5:18 PM
    What’s a good way to read YAML and/or CSV?
    a
    • 2
    • 1
  • z

    zt

    09/03/2022, 7:55 AM
    Is there some library I can use for storing data efficiently? I've tried out exposed and ktorm but they are sorta confusing to me. i just want something simple but fast
  • e

    egek

    09/03/2022, 10:58 AM
    Modernstorage
  • h

    Hassaan

    09/03/2022, 1:00 PM
    As postfix has greater precedence than prefix, then why
    var num = 0
    println(--num + num++) // equals to -2 instead of 0
    a
    e
    +3
    • 6
    • 14
  • n

    NelsonC

    09/03/2022, 6:46 PM
    Any way to make an object such as a sound start on background without a button on Android studio? I can make it as a button to start but haven't found resources to make it start automatically as the activity starts . Would really appreciate the help. Using kotlin language that is
    g
    • 2
    • 1
  • r

    rednifre

    09/03/2022, 8:06 PM
    What’s the function that sorts a list of things into buckets, like partition(list: List<A>, key: (A -> B)): Map<B, List<A>> ?
    t
    • 2
    • 1
  • m

    Mateusz Konieczny

    09/05/2022, 4:17 PM
    Is it normal that one adds useless
    else
    branch even if not needed in Kotlin 1.7? See say https://github.com/streetcomplete/StreetComplete/commit/1972a7139bff92e894474d1d3d1969b83da2d375 For example
    private fun wat(element: StackUnderflow) {
        when (element) {
            is Unicorn -> {}
            is Multicorn -> {}
            else -> {}
        }
    }
    requires useless
    else
    where
    sealed class StackUnderflow
    sealed class Unicorn(val surface: Surface) : StackUnderflow()
    sealed class Multicorn : StackUnderflow()
    sealed class Tricorn(val surface: Surface) : Multicorn()
    sealed class Doublecorn(val surface: Surface) : Multicorn()
    is imported from another file.
    j
    • 2
    • 24
  • l

    Laurent Laborde

    09/05/2022, 4:27 PM
    i just found out about lateinit, this is super cool so that we don’t have to construct something using null 😒miling_face_with_3_hearts:
    k
    r
    j
    • 4
    • 7
  • l

    Laurent Laborde

    09/05/2022, 6:25 PM
    Any idea how to retrieve the version defined in build.gradle.kts so that i can use it in my code ?
    h
    y
    • 3
    • 8
  • m

    marlonlom

    09/05/2022, 10:23 PM
    How to use
    reified
    in a function that, when using a generic function, shows a compiler error message? The compile error message:
    Cannot use 'T' as reified type parameter. Use a class instead.
    j
    • 2
    • 4
  • l

    Laurent Laborde

    09/06/2022, 5:37 AM
    there is something i don’t understand. is everything non-nullable by default (unless i use “?”) or is there something specific to write to ensure that something can’t be nulled ?
    a
    e
    s
    • 4
    • 7
  • s

    SeniorZhai

    09/06/2022, 9:03 AM
    I found this problem when I was using
    if-else-if-else
    s
    m
    +2
    • 5
    • 13
  • s

    Siegfried Kiermayer

    09/06/2022, 4:24 PM
    I'm trying to replixate the kogito quarkus example where they use this injection method:
    @Named("approvals")
        @Inject
        Process<? extends Model> approvalsProcess;
    When i try the same thing in Kotlin, i'm only getting an
    [error]: Build step io.quarkus.arc.deployment.ArcProcessor#validate threw an exception: javax.enterprise.inject.spi.DeploymentException: javax.enterprise.inject.AmbiguousResolutionException: Ambiguous dependencies for type org.kie.kogito.process.Process<? extends org.kie.kogito.Model> and qualifiers [@Default]
    exception. The same constructor injection 'way' actually works:
    @ApplicationScoped
    class FooBar (
        @Named(value = "approvals")
        private val approvalsProcess: Process<out Model>
            ){
    But now i need to do the injection in my Test class for a unit test and i can't use this as its not allowed. only propery assignment is allowed
  • s

    Siegfried Kiermayer

    09/06/2022, 4:50 PM
    Apparently doing this:
    @field: Named(value = "approvals")
    actually works. No clue what this should do
    r
    e
    • 3
    • 15
  • t

    Teimatini Marin

    09/06/2022, 10:51 PM
    Hi experts I can read in this kt.academy article that
    Fan-out
    Multiple coroutines can receive from a single channel; however, to receive them properly we should use a for-loop (consumeEach is not safe to use from multiple coroutines)
    I wonder if this statement regarding consumeEach is still accurate? In which sense it is not safe?
    f
    • 2
    • 4
  • p

    PoisonedYouth

    09/07/2022, 7:21 AM
    Hello, I have a questions regarding transformation of list:
    val result = myList
                .filter { it.nullableProperty != null }
                .map { it.nullableProperty!!.fromAccount }
    Why do I have to use the non-null asserted call in the map step?
    j
    s
    r
    • 4
    • 6
  • y

    y

    09/07/2022, 8:22 AM
    is
    try-catch
    idiomatic in Kotlin?
    s
    s
    c
    • 4
    • 5
  • j

    Joffrey

    09/07/2022, 10:19 PM
    But is it actually an instance of that class? You cannot cast arbitrary instances to arbitrary types. You can only cast instances that are actually already of that type at runtime, but for which this fact is not known at compile time.
    y
    • 2
    • 1
  • z

    zt

    09/08/2022, 12:31 AM
    Is there some library I can use to generate graphs as image files? I just need some way to convert a map of values into a pie chart then export as a png or something similar
    m
    • 2
    • 1
  • j

    Jari Tuikka

    09/08/2022, 12:08 PM
    Is there static analysis tool which work for both kotlin and java?
    g
    s
    r
    • 4
    • 4
  • y

    y

    09/08/2022, 2:03 PM
    is there some way to do
    filterNotNull().filter { //… }
    with one function?
    s
    r
    c
    • 4
    • 6
  • y

    y

    09/08/2022, 2:04 PM
    better yet, is there an equivalent of
    filter_map()
    from, say, Rust?
  • s

    sreich

    09/08/2022, 6:39 PM
    I have java code that uses the pattern of say Inquiry().status(sts).notes(blah). Which enables chaining. what can i do from a kotlin aspect to define a similar class as that? the fields are not required, so you may want to set only 2 of those 3
    r
    v
    e
    • 4
    • 17
  • t

    Thomas Dziedzic

    09/08/2022, 8:37 PM
    hey all, is there a preferred or "standard" way to do http calls in kotlin? like an external library or some built in http library
    l
    m
    • 3
    • 3
Powered by Linen
Title
t

Thomas Dziedzic

09/08/2022, 8:37 PM
hey all, is there a preferred or "standard" way to do http calls in kotlin? like an external library or some built in http library
l

Landry Norris

09/08/2022, 8:41 PM
I’d think #ktor would be the closest to a ‘standard’ for Kotlin as a whole since it’s first-party.
t

Thomas Dziedzic

09/08/2022, 8:43 PM
https://ktor.io/docs/create-client.html#use-client looks like it is exactly what I'm looking for thanks!
m

Matteo Mirk

09/11/2022, 7:55 AM
You can also use http4k client or some other libs, as you prefer: https://kotlin.libhunt.com/categories/5616-http-clients Unfortunately there’s no HTTP client in the standard library.
View count: 15