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
announcements
  • j

    Javier

    08/18/2020, 11:22 PM
    Kotlin Test and annotation have been migrated so now is not necessary to add
    -common
    to implement them?
    i
    s
    • 3
    • 4
  • j

    Joseph Magara

    08/18/2020, 11:51 PM
    Hey guys, does anyone know when StateFlow (and MutableStateFlow) will be released? As far as I know, it's still at the experimentation phase.
    z
    • 2
    • 5
  • v

    Vampire

    08/19/2020, 3:02 AM
    Can Kotlin do something like this just in valid:
    inline fun <reified T> options(options: T.() -> Unit): T = object : T {}.apply(options)
    ?
    s
    • 2
    • 3
  • l

    lib

    08/19/2020, 3:13 AM
    what is the Kotlin technology stack looks like ? compare with Java :
    n
    • 2
    • 5
  • p

    Paul Woitaschek

    08/19/2020, 9:27 AM
    Can I tall the kotlin plugin to not add the sdlib for a specific module? I have a module that contains my android lint checks and there no implementation dependencies are allowed but only compileOnly ones.
    b
    • 2
    • 12
  • o

    Orhan Tozan

    08/19/2020, 9:46 AM
    My IDE (Android Studio) automatically updated the kotlin compiler plugin version to 1.4. Now my compiler is giving imaginary errors, probably because my gradle is still on 1.3.72 ( I cant change to 1.4 because of kotlinx.serialization breaking changes, sigh). How do I downgrade my IDE's kotlin compiler plugion from 1.4 to 1.372?
    ➕ 1
    👀 1
    j
    s
    • 3
    • 7
  • p

    Pablo

    08/19/2020, 9:55 AM
    How is the idiomatic way to modify the value of a list for the desired object? I mean instead of doing it manually like list[1].name = "name" is there any other idiomatic way to do so? I want to modify all of the values of a list with different "names".
    n
    • 2
    • 2
  • w

    waltermcq

    08/19/2020, 1:22 PM
    Given how Slack can end up as a "black hole" for otherwise high quality information, does anybody make a periodic digest of any of the kotlin language slack?
    👍 4
    👀 1
    b
    j
    • 3
    • 6
  • l

    Lqncer

    08/19/2020, 3:38 PM
    Hopefully this is the right channel to ask my question, if not please redirect me. I heard opinions that Kotlin is way quicker to write than Java and you can pump our projects/code faster, is this true? If so, by how much (% wise)
    t
    w
    +2
    • 5
    • 5
  • c

    colintheshots

    08/19/2020, 5:05 PM
    Since upgrading to Kotlin 1.4.0, I can't seem to use String.toBoolean() anymore. I always get the deprecation warning:
    toBoolean(): Boolean' is deprecated. Use Kotlin compiler 1.4 to avoid deprecation warning.
    It seems like this is not a well-functioning deprecation warning. There's no easy way to select the String?.toBoolean() version instead. Even if I cast to String?, the 1.4 compiler won't let me call String?.toBoolean() explicitly. It seems like a compiler bug.
    l
    m
    +2
    • 5
    • 8
  • m

    Mark Buikema

    08/20/2020, 10:08 AM
    I have a challenge for you guys: I have to create a domain model for a PaymentMethod. From the API I receive 2 values for each payment method: • id • transaction cost Let's say I have 3 different types of payment methods: • PayPal (id=1) • CreditCard (id=2) • Cash (id=3) I want to have subclasses for each payment method. The ID that is received from the API should be mapped to an instance of the matching subclass. I want to have subclasses because each payment method has some static data connected to it, that is defined client-sided (e.g. name, etc). If API returns an unknown ID, it can be ignored. Ultimately I would like to have a function in companion object of PaymentMethod:
    sealed class PaymentMethod {
      abstract val transactionCost: BigDecimal
      
      data class PayPal(...) : PaymentMethod
      data class CreditCard(...) : PaymentMethod
      data class Cash(...) : PaymentMethod
    
      companion object { 
        fun create(id: Long, transactionCost: BigDecimal) : PaymentMethod {
          // TODO
        }
      }
    }
    Also I want to have a single source of truth for defining which ID belongs to which subclass (only define it once). Would like to hear some tips on how to implement this. If you think there are better approaches (except for modifying API) than what I want, feel free to suggest.
    j
    m
    m
    • 4
    • 9
  • e

    Esa

    08/20/2020, 10:53 AM
    Hi, I have some Iterable extension functions I wish to contribute to the standard lib (this one I guess). I see there are already over 4000 branches. If I make a PR, will it be seen? I guess I'm just a little perplexed as there's no contributor instructions on the github 🙂 Any comments appreciated
    u
    • 2
    • 2
  • a

    Animesh Sahu

    08/20/2020, 11:29 AM
    How to view definition of the expect function from standard-library? Example: ArrayT.sort(). I tried to find a way in the Intellij, but so far no luck :<
    a
    • 2
    • 11
  • p

    Phani Mahesh

    08/20/2020, 3:28 PM
    QQ: If I am a library author, can I update the library's kotlin version without requiring its consumers to update as well? Specifically 1.3.72 -> 1.4.0
    ➕ 1
    z
    a
    u
    • 4
    • 11
  • k

    Karlo Lozovina

    08/20/2020, 6:26 PM
    is there a way to enumerate all subclasses of a given class and instantiate single instance of each? without going into too much metaprogramming etc...
    n
    r
    • 3
    • 11
  • k

    Karlo Lozovina

    08/20/2020, 6:28 PM
    so sealedSubclasses works... now just to instantiate them?
    e
    • 2
    • 1
  • e

    edrd

    08/20/2020, 7:22 PM
    I'm experiencing a really smoother IDE experience with Kotlin 1.4 due to the performance improvements. Couldn't be happier. Thanks Kotlin team 🙂
    😃 6
    a
    • 2
    • 2
  • a

    alwyn

    08/20/2020, 8:50 PM
    Why is it that the following code has no errors:
    fun calculateNumberOfLengthBytes(data: ByteArray): Int {
        val l: Int = data.size
        return when {
            l < 128 -> 1
            l < 16384 -> 2
            l < 2097152 -> 3
            l < 268435456 -> 4
            else -> 5
        }
    }
    but, the following complains about "Incompatible types: Boolean and Int" in the comparisons
    val data = byteArrayOf(5, 6, 7)
    when(val l: Int = data.size) {
        l < 128 -> 1
        l < 16384 -> 2
        l < 2097152 -> 3
        l < 268435456 -> 4
        else -> 5
    }
    d
    a
    • 3
    • 6
  • x

    xii

    08/20/2020, 11:41 PM
    is there a slack server similar to this one but for spring framework?
    b
    k
    • 3
    • 3
  • e

    eygraber

    08/21/2020, 1:49 AM
    I'm trying to update to Kotlin 1.4 and I have a Sequence<Long> that I call
    max
    on. I get a deprecation warning, so I run the "Replace with maxOrNull" fix, and it replaces
    .max()
    with
    maxOrNull()
    . So I put the
    .
    in front, and I get an unresolved reference error. There is no fix to import it. So I manually write the import (
    import kotlin.sequences.maxOrNull
    ), and I still get the unresolved reference error, and the import is gray (unused).
    If I open
    _Sequences.kt
    I see
    public fun <T : Comparable<T>> Sequence<T>.maxOrNull(): T?
    Is there some trick that I'm missing here, or should I report this on YouTrack?
    • 1
    • 1
  • k

    kevin.cianfarini

    08/21/2020, 3:30 AM
    Not strictly Kotlin related, but does anyone know why the following JMH benchmark code
    @Fork(1)
    @Warmup(iterations = 5, time = 2)
    @Measurement(iterations = 5, time = 2)
    @State(Scope.Benchmark)
    @BenchmarkMode(Mode.AverageTime)
    @OutputTimeUnit(TimeUnit.MICROSECONDS)
    open class Sha1Benchmark {
    
    }
    produces the corresponding error?
    > Task :okio:jvm:jmh:jmhRunBytecodeGenerator FAILED
    Processing 15 classes from /home/kevin/code/okio/okio/jvm/jmh/build/classes/java/jmh with "reflection" generator
    Processing 2 classes from /home/kevin/code/okio/okio/jvm/jmh/build/classes/kotlin/jmh with "reflection" generator
    Writing out Java source to /home/kevin/code/okio/okio/jvm/jmh/build/jmh-generated-sources and resources to /home/kevin/code/okio/okio/jvm/jmh/build/jmh-generated-resources
    
    FAILURE: Build failed with an exception.
    
    * What went wrong:
    Execution failed for task ':okio:jvm:jmh:jmhRunBytecodeGenerator'.
    > A failure occurred while executing me.champeau.gradle.JmhBytecodeGeneratorRunnable
       > Generation of JMH bytecode failed with 1 errors:
           - Benchmark classes should not be final.
            [com.squareup.okio.benchmarks.Sha1Benchmark]
    • 1
    • 1
  • f

    frank

    08/21/2020, 4:43 AM
    [Solved] I'm testing
    java.nio
    in Kotlin and I have a question: Why don't work
    member references
    to function is this case? *I know that with
    Files.isDirectory(it)
    work i*t
    val stream = Files.list(folder) 
    val files  = stream.filter {  it != null && Files::isDirectory } // error in Files::isDirectory
                       .map    { it!! }
    Error Msg:
    Type mismatch.
    Required: Boolean
    Found: KFunction2<Path!, Array<(out) LinkOption!>!, Boolean>
    PD: Sorry, if this topic doesn't have to be in this channel, but I didn't find JVM channel.
    j
    • 2
    • 8
  • v

    Vampire

    08/21/2020, 9:44 AM
    Can I somehow call a suspending function inside a
    Sequence#map
    lambda? Or if not, is there some other construct to achieve the result?
    s
    • 2
    • 2
  • s

    Srki Rakic

    08/21/2020, 1:20 PM
    how to combine two immutable lists into new immutable list? or add element to a list to create anew list. Something like newImmutableList = immutableList + element?
    d
    • 2
    • 1
  • s

    Sam Garfinkel

    08/21/2020, 2:51 PM
    Is there a shorthand way of having a
    MutableList<>
    property with a getter that returns it as a
    List<>
    ?
    s
    j
    • 3
    • 4
  • x

    xii

    08/21/2020, 2:55 PM
    im working with an async library that returns a CompletableFuture; how could i convert it into a coroutine? (like Mono.fromFuture() does)
    a
    • 2
    • 16
  • k

    Karlo Lozovina

    08/21/2020, 5:04 PM
    can Kotlin somehow match nested classes with
    when
    expression? something like Haskell can do, like
    (Foo (Bar (Baz x))) -> ... something(x)
    ?
    s
    • 2
    • 2
  • p

    Philipp Mayer

    08/21/2020, 7:52 PM
    Is there anyone with knowledge about a project/github repository which makes some real use of kotlinx.html (not just hello world)? Would love to look into that. Thanks!
    h
    • 2
    • 7
  • g

    Gunslingor

    08/22/2020, 3:09 AM
    Any one had a problem with CSSBuilder removing periods on class names?
    ".clearfix" { clear = Clear.both }
    in browser becomes
    clearfix { clear = both }
    So confused. It works elsewhere, but this is like another layer of css in.
    • 1
    • 1
  • m

    Mehdi Haghgoo

    08/22/2020, 7:55 AM
    In Code, I usually press Ctrl + Shift + P or (Cmd + Shift + P) to open Command search.
    y
    n
    b
    • 4
    • 3
Powered by Linen
Title
m

Mehdi Haghgoo

08/22/2020, 7:55 AM
In Code, I usually press Ctrl + Shift + P or (Cmd + Shift + P) to open Command search.
y

Yaroslav Chernyshev [JB]

08/22/2020, 8:01 AM
Try
Cmd + Shift + A
shortcut
❤️ 1
n

Nikky

08/22/2020, 9:26 AM
and for all the other stuff double tap shift
b

Ben Woodworth

08/22/2020, 6:36 PM
It's also the first entry in the
Help
menu
View count: 4