https://kotlinlang.org logo
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
  • k

    kotlinforandroid

    06/30/2022, 11:54 AM
    I have an annotation where I want to be able to reference Android Compose ImageVectors using a field. For example
    annotation class Ref(val icon: ImageVector)
    Is this somehow possible to accomplish? I guess I can use
    KClass<out ImageVector>
    but I do not really understand how that would interact since all material icons from compose are defined as `val Icons.Filled.Add`for example.
  • s

    smit01

    06/30/2022, 11:57 AM
    will Kotlin-Conf23 Amsterdam workshop and talk videos be available on Kotlin official YouTube channel for students like me who can not afford to travel at moment?
    👍 3
    y
    • 2
    • 1
  • h

    hfhbd

    07/01/2022, 7:15 AM
    If you use a ReadWriteProperty with the by operator, is there any possibility to access the underlying delegate? Ideally, I want to override the toString method but keep using idiomatic code
    j
    • 2
    • 11
  • k

    Klitos Kyriacou

    07/01/2022, 4:45 PM
    I have a use case for a
    Map<Int, String>
    . Each map has only a small handful of entries. I need to keep many thousands of these maps in memory. 99% of the time the
    Int
    key is small, between 1 an 10. If it was guaranteed to always be that small, the most efficient implementation of such a map would use an
    Array<String?>
    . However, 1% of the time there would be a key that would be a very large integer, so a simple array is unusable. Yet if I use a
    HashMap
    or
    TreeMap
    I would be wasting memory for 99% of the time by using a sub-optimal implementation. Is there any specialized Map that uses a strategy of changing internal implementation depending on the value of the key?
    r
    m
    y
    • 4
    • 6
  • j

    julian

    07/01/2022, 10:13 PM
    A function reference passed as an argument to an inline function will not be inlined. Is that correct? That's what it looks like from the bytecode, but I'm on shaky ground when making sense of bytecode.
    e
    d
    s
    • 4
    • 11
  • h

    Hassaan

    07/02/2022, 12:33 PM
    Isn’t ‘protected’ has lesser visibility than ‘internal’ ? Then why following:
    y
    e
    • 3
    • 8
  • o

    oday

    07/02/2022, 4:13 PM
    so if I’m using Kotlin 1.7.0, does “K2” come included or something? how do I enable it, how do I try it?
    r
    • 2
    • 1
  • l

    Loney Chou

    07/04/2022, 5:28 AM
    Is it possible to generate overriden methods from java which have non-null parameters by default? Right now it always marks every parameter as nullable if is not primitive.
    r
    • 2
    • 2
  • p

    Pablo

    07/04/2022, 7:23 AM
    Hello how can I update a list for instance. I have this
    fun getList() : List<Foo>
    
    val myList = getList()
    Now I want depending on my flag sort or not that list, I've tried it but did not work
    val myList = getList().apply { if(bar) mySorter.sort(this) }
    Is there any kotlinian way to sort the list instead of creating a new val?
    s
    j
    • 3
    • 2
  • r

    reactormonk

    07/04/2022, 9:26 AM
    Can I have an
    enum class
    with an "other value"? Aka
    enum class Status(val value: Int) {
      Present(2),
      Absent(1),
      Error(value)
    }
    ?
    j
    • 2
    • 16
  • r

    reactormonk

    07/04/2022, 1:47 PM
    Is
    x and 0xFF.toByte()
    a noop? Aka
    x and 0xFF.toByte() == x
    is always true?
    j
    s
    • 3
    • 17
  • a

    Andrew Cerne

    07/04/2022, 3:14 PM
    👋 Hello, team!
    👋 4
    👋🏼 1
  • r

    reactormonk

    07/04/2022, 4:50 PM
    How would y'all represent bit fields? Aka convert them to the
    Byte
    to send them to the wire and back, and preferably a reasonable API along the way.
    j
    k
    e
    • 4
    • 19
  • c

    Chris Fillmore

    07/04/2022, 8:23 PM
    Is it safe to cast
    T & Any
    to
    T
    ?
    j
    • 2
    • 7
  • r

    reactormonk

    07/04/2022, 8:54 PM
    What's the syntax for two bounds in generics?
    fun <A: Enum<A>, Positional> EnumSet<A>.toByte(): Byte {
    Apparently it's not
    ,
    nor
    :
    e
    • 2
    • 2
  • a

    Alan B

    07/05/2022, 1:56 PM
    I swear I have long covid and brain fog or something. Is there an idiomatic way in Kotlin to
    map
    while supplying the map-like operation with a list of functions (or vararg) to apply to each element, rather than a single transformation? basically
    collection.mapAll(transformers: List<(T) -> R>)
    sequence.mapAll(transformers: List<(T) -> T>)
    I want to supply a list of transformers so I don’t have to do something like:
    sequence.map(::first)
    .map(::second)
    .map(::third)
    would be:
    sequence.map(tranformers)
    j
    w
    +3
    • 6
    • 19
  • m

    Marcus Brito

    07/05/2022, 2:29 PM
    hey guys — is there any way I can keep a data class property declared as
    Long
    exposed as a boxed
    java.lang.Long
    , as opposed to a
    long
    primitive? Other than making it nullable, that is.
    s
    • 2
    • 5
  • r

    reactormonk

    07/05/2022, 2:43 PM
    How do I write tests? Do you use https://kotlinlang.org/api/latest/kotlin.test/ ? There's no doc linked form there? 🤔
    a
    h
    k
    • 4
    • 6
  • p

    Pascal Gerrist

    07/05/2022, 3:19 PM
    Hey folks! Does anyone have experience with SimpleXML? I'm trying to parse XML into an object but getting some errors.
    m
    • 2
    • 9
  • n

    nkiesel

    07/05/2022, 7:25 PM
    I recently (my guess is: after upgrading to Kotlin 1.7.0) have issues with IntelliJ not seeing Java changes in my Kotlin code. Concrete example is that I had a simple Java pojo with a default constructor which was called from Kotlin. I now added a second constructor and changed the Kotlin code to use that. That does compile and works, but IntelliJ shows an "Too many arguments for public constructor" error. I guess invalidating caches and restarting IntelliJ will fix this, but that is of course cumbersome. Is that a known issue?
    a
    • 2
    • 2
  • m

    Monroe Walker

    07/05/2022, 10:16 PM
    Hey! I asked this on the forum already: https://discuss.kotlinlang.org/t/compilekotlin-execution-time-seems-to-randomly-vary-within-2-10-second-range/25154/2 but am also asking here in case people check this more often - my compileKotlin step of my gradle build varies in execution time within a window of about 2-10 seconds. I'm trying to figure out why it takes longer when it does but I'm not sure what to look into. Any advice?
    s
    • 2
    • 3
  • e

    Erik

    07/06/2022, 3:06 PM
    (If wrong channel, let me know!) If a function has multiple arguments, e.g.:
    fun f(x: Int, y: Int) = TODO()
    then it is possible to autocomplete them with arguments like so: Type:
    f
    , then it should suggest to autocomplete
    f
    and then you press some key so that the IDE (Android Studio or IntelliJ) now completes it to
    f(x = , y = )
    , with the cursor just before the comma so you can continue typing, e.g.
    1
    and then you press tab to move the cursor to the next argument (
    y =
    ) so you can continue typing. I'm sitting right next to a colleague who can do this in one project. But not in another, so we think it's a project setting that's somehow enabled in one project, but not in the other. This would be super helpful to enable this in all our projects, but how do we do that? What's this feature called? Is there a keystroke to use? Is this something that can be enabled?
    y
    • 2
    • 10
  • s

    Sangeet

    07/06/2022, 3:30 PM
    Any idea why lint or kotlin compiler is not showing error for below code
    fun <T : CharSequence> doSomething(): T {
        return String() as T
    }
    
    class Something(intValue: Int)
    
    Something(doSomething()) // Doesn't show any compile error
    It seems that it is automatically casting CharSequence to Number and throwing error in runtime.
    c
    s
    e
    • 4
    • 6
  • m

    Monroe Walker

    07/06/2022, 6:01 PM
    Does Kotlin DSL offer a way to require a pattern for strings to follow? Either by regex or some validator function?
    e
    r
    • 3
    • 16
  • a

    allan.conda

    07/07/2022, 4:27 AM
    is there a way to cache the map function of a flow for distinct events so it doesn’t recompute for the same value?
    flow(1, 1, 2, 2, 3).map { expensiveMapping(it) }.collect()
    i
    h
    • 3
    • 7
  • c

    Colton Idle

    07/07/2022, 4:07 PM
    Not sure if this is the right spot, but is there a reputable library for Kotlin for public key RSA encryption? I just need to encrypt a string. My iOS team is using https://github.com/TakeScoop/SwiftyRSA but i cant find something like that for kotlin.
    o
    e
    a
    • 4
    • 23
  • w

    Will_505

    07/07/2022, 7:26 PM
    Hey! I have come across an error in the IntelliJ IDE in Main.kt the tutorial i am following is telling me to declare my functions like so but i am getting issues with the compiler. the code:
    fun sayHello(itemToGreet:String) = println("Hello $itemToGreet")
    
    fun main() {
        sayHello(itemToGreet: "Kotlin")
        sayHello(itemToGreet: "World")
    
    }
    The error:
    l
    • 2
    • 17
  • a

    Alex Stelmachonak

    07/08/2022, 1:18 AM
    Hi. Something strange happening to my gradle (groovy) project when trying to update kotlin version from 1.6.21 to 1.7.10:
    An exception occurred applying plugin request [id: 'org.jetbrains.kotlin.jvm', version: '1.7.10']
    > Failed to apply plugin 'org.jetbrains.kotlin.jvm'.
       > The task 'compileKotlin' (org.jetbrains.kotlin.gradle.tasks.KotlinCompile) is not a subclass of the given type (org.gradle.api.tasks.compile.AbstractCompile).
    
    * Try:
    > Run with --info or --debug option to get more log output.
    > Run with --scan to get full insights.
    
    * Exception is:
    org.gradle.api.plugins.InvalidPluginException: An exception occurred applying plugin request [id: 'org.jetbrains.kotlin.jvm', version: '1.7.10']
    	at org.gradle.plugin.use.internal.DefaultPluginRequestApplicator.exceptionOccurred(DefaultPluginRequestApplicator.java:223)
    Looks like something simple, but as often with gradle, simple things are not simple to find 😞 Any ideas anyone?
    d
    t
    • 3
    • 8
  • r

    reactormonk

    07/08/2022, 9:56 AM
    How come the IDE complete
    CardStatus.Companion.Present
    instead of
    CardStatus.Present
    here?
    sealed class CardStatus(val value: Int) {
        companion object {
            fun fromInt(int: Int): CardStatus {
                return when(int) {
                    255 -> PowerSavingMode
                    3 -> Powered
                    2 -> Present
                    1 -> Absent
                    else -> Error(int)
                }
            }
    
            object PowerSavingMode: CardStatus(255)
            object Powered: CardStatus(3)
            object Present: CardStatus(2)
            object Absent: CardStatus(1)
            data class Error(val errorValue: Int): CardStatus(errorValue)
        }
    }
    h
    k
    • 3
    • 4
  • s

    Slackbot

    07/08/2022, 10:35 AM
    This message was deleted.
Powered by Linen
Title
s

Slackbot

07/08/2022, 10:35 AM
This message was deleted.
View count: 6