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

    Kasule Moses

    06/26/2021, 1:57 PM
    How can I easily read and understand kotlin coroutines. Which best resources can you recommend
    g
    s
    n
    • 4
    • 3
  • u

    user

    06/26/2021, 3:00 PM
    message has been deleted
    c
    • 1
    • 1
  • n

    nilTheDev

    06/27/2021, 7:12 AM
    Hello Devs. I just wanted to taste
    coroutines
    . Unfortunately, I haven't been able to use the library
    kotlinx
    in
    idea
    for two hours. I have downloaded the library through
    Maven
    . 1. Tried invalidating caches. 2. Rebuilt project. 3. Tried using it in a fresh project. 4. Even
    intellij
    is suggesting
    kotlinx
    in auto-completion. 5. Still it says
    unresolved reference
    I have tried most of the solutions on the web. But nothing worked. 🙄
    c
    j
    g
    • 4
    • 10
  • m

    marzelwidmer

    06/27/2021, 11:01 AM
    Hello Have somebody any tip I migrate my
    data classes
    to
    value classes
    now
    sonar
    tell me this is not under test anymore…
    • 1
    • 1
  • s

    SomeAbsolutelyRandomStuff

    06/27/2021, 11:53 AM
    I have a very serious issue with IDEA.... it uses over 60% of my CPU and RAM and just freezes my entire PC whenever I run my code
    :not-kotlin: 4
    c
    • 2
    • 1
  • s

    SomeAbsolutelyRandomStuff

    06/27/2021, 11:54 AM
    I've also limited the heap to a maximum of 500MB but it insists of using almost 2GB of RAM and 60+% CPU
    :not-kotlin: 5
    :thread-please: 5
    c
    • 2
    • 1
  • s

    SomeAbsolutelyRandomStuff

    06/27/2021, 11:56 AM
    Oh and it uses like 40-50% CPU and approximately 700MB RAM when idle
    :thread-please: 5
    🤦‍♂️ 4
    :not-kotlin: 6
    c
    • 2
    • 1
  • k

    Kulwinder Singh

    06/27/2021, 4:06 PM
    Hi, How can i fill
    prevItems
    and
    nextItems
    of below data class , i have tried
    recursion
    but it caused infinite loop because we have to find next and previous both but if i try with either previous or next then there is no infinite loop.
    data class Root(val item: Int, val prevItems: List<Root>, val nextItems: List<Root>)
    Suppose i have data for
    item
    is => 1,2,3,4,5 then result i wanted is =>
    Root(item: 1, prevItems: [], nextItems: [2,3,4,5])
    Root(item: 2, prevItems: [1], nextItems: [3,4,5])
    Root(item: 3, prevItems: [1,2], nextItems: [4,5])
    Root(item: 4, prevItems: [1,2,3], nextItems: [5])
    Root(item: 5, prevItems: [1,2,3,4], nextItems: [])
    *for making it short i am using 1,2,3… in prevItems/nextItems instead of
    Root
    object
    what approach should i use to calculate above? also is there any kotlin collection function can help here ?
    c
    b
    +4
    • 7
    • 11
  • h

    hfhbd

    06/28/2021, 1:07 PM
    Hey, I want to precise my
    Double
    usage in my project with physical classes, like kiloWatt per Hour. before:
    data class Holder(val output: Double)
    now:
    data class Holder(val output: Kwh)
    
    value class Kwh(val value: Double)
    Now I want to use the default math operators, plus, minus unaryPlus, unaryMinus. Is there any possibility to create default operator functions without copy paste?
    b
    s
    • 3
    • 5
  • d

    David Smith

    06/28/2021, 4:56 PM
    I’m having a weird error that I don’t understand. I have a kotlin “type-safe builder” for some html and in it I have 2 child elements, one of which is inside a
    when
    div {
      h1 { ... }
      when (x) {
        A -> +"text"
        B -> div { ... }
      }
    }
    The actual model that this produces reverses the order of the
    h1
    and the other child. The order is correct if I have the same but without the
    with
    construct. The same issue happens with
    if
    . Am I misunderstanding something about execution order in lambdas or something?
    c
    • 2
    • 3
  • s

    Shawn

    06/28/2021, 5:17 PM
    @Pratik Tandel https://kotlinlang.org/docs/guidelines.html
    p
    • 2
    • 5
  • n

    nordiauwu

    06/28/2021, 6:31 PM
    What is the right way to synchronize threads in common code? I'm currently using
    val mutex = Mutex()
        
    runBlocking { 
        mutex.withLock {
            ... 
        }
    }
    as a workaround, but not sure if it's a good practice.
    d
    a
    • 3
    • 22
  • a

    Ayfri

    06/29/2021, 12:34 AM
    Hey, do you know any good front-end Kotlin framework ? I want to create a simple website but it's my first time and I don't know what to choose in Kotlin for doing this 🤔
    j
    s
    +3
    • 6
    • 7
  • r

    Rak

    06/29/2021, 8:21 AM
    Are interfaces still a good idea in Kotlin? I ask because most of the time there is only one implementing class and mocking is a non-issue in tests.
    c
    n
    t
    • 4
    • 7
  • a

    andylamax

    06/29/2021, 9:33 AM
    I have the following kotlin code
    class Wrapper(val value: ULong)
    When I try instantiating it from Java I get
    Wrapper w = new Wrapper(5000L);
    It says that the constructor is private. How do I instantiate such a class?
    d
    e
    • 3
    • 9
  • a

    althaf

    06/29/2021, 10:14 AM
    Hi , is there a way to convert this to map based instead of for()
    for (it in this) {
    
            if (!isSendToRepairOrRejected) {
                isSendToRepairOrRejected =
                    (it?.state == SubActions.SEND_FOR_REPAIR.name || it?.state == StatusName.REJECTED.name)
    
                result.add(
                    WorkFlowStateData(
                        stateName = it?.stateName ?: "",
                        displayName = it?.displayName ?: "",
                        isCompleted = it?.status.equals(
                            S2BConst.STATUS_CLOSED,
                            true
                        ) || it?.status.equals(
                            S2BConst.STATUS_IN_PROGRESS,
                            true
                        ),
                        // TODO try to evaluate propervalue
                        currentState = true
                    )
                )
            } else {
                break
            }
        }
    s
    • 2
    • 4
  • j

    Jolan Rensen [JetBrains]

    06/29/2021, 3:17 PM
    Hey, I wondered if there may be something like an annotation that can be added to a Java or Scala method to make it invisible for Kotlin but still visible for those languages.
    n
    s
    • 3
    • 6
  • f

    Fung.Yam

    06/30/2021, 6:43 AM
    There are two solutions about Package-private visibility in the kotlin feature survey. It seems good to have some way to mark a package like suggested in solution 2, but just curious that how will it be implemented. Will it be something like init.py in python?
    d
    • 2
    • 2
  • c

    Ch8n

    06/30/2021, 8:31 AM
    Hi Guys I'm interested in learning open gl and image processing on Android, if anyone can share good resources could be great help 🙌🏻
    :google: 5
    :not-kotlin: 9
    s
    • 2
    • 1
  • c

    CLOVIS

    06/30/2021, 10:24 AM
    On the Kotlin survey: I'm really not a fan of introducing
    static
    to the language. The semantic relationship between classes and objects are a beautiful way to remove complexity to the language while adding new features. To my understanding, the proposal exists for two reasons: 1. For performance reasons 2. To allow extension functions on classes that do not have a companion object I don't think it's a good idea to introduce
    static
    for performance reasons (the language should be about semantics, the compiler should handle performance). If it's not possible to do automatically by the compiler (because it would break backward-compatibility, or whatever) then at most it should be a JVM-specific annotation. I don't think a new keyword is necessary for classes that do not have a companion object. I think Kotlin should allow:
    fun Foo.Companion.bar() = ...
    even if Foo doesn't have a Companion. Obviously the compiler will have to replace the companion by something else, but that's not really a big deal (it will be invisible in Kotlin code, and extension functions are already a bit weird from Java code, so as long as it's not something extremely strange I think it's alright)
    e
    r
    n
    • 4
    • 53
  • s

    spierce7

    06/30/2021, 2:40 PM
    Oh wow - the survey is very difficult. It’s VERY challenging choosing only 3. I’m having to categorize things and rate them based on how much they would improve my quality of life.
    b
    d
    +4
    • 7
    • 23
  • u

    user

    06/30/2021, 3:48 PM
    message has been deleted
    m
    • 1
    • 1
  • s

    Saiedmomen

    06/30/2021, 4:24 PM
    Is Google Maven down?
    🇳🇴 2
    c
    • 2
    • 10
  • m

    MAYANK SINGHAL

    06/30/2021, 4:56 PM
    Can anyone please help in making this type of progress bar
    🤦 4
    :not-kotlin: 16
    v
    • 2
    • 1
  • t

    TheOnlyTails

    06/30/2021, 10:34 PM
    If I have a class (in java) like so:
    class ExampleJava {
        private static int x = 10;
    
        public static int getX() {
            return x;
        }
    
        public static void setX(int num) {
            x = num;
        }
    }
    Can I do something like this in kotiln? If no, why?
    println(ExampleJava.x)
    ExampleJava.x = 1
    e
    • 2
    • 4
  • a

    Ayfri

    07/01/2021, 7:30 AM
    https://copilot.github.com/ Imagine this with Kotlin in Intellij :o
    🤖 2
    ❤️ 1
    c
    c
    +2
    • 5
    • 5
  • m

    Michael Grigoryan

    07/02/2021, 5:02 AM
    Hi all 👋 I want to translate and make a contribution to Kotlin docs in my native language, can you please tell me where should I get started?
    l
    • 2
    • 9
  • a

    Alina Dolgikh [JB]

    07/02/2021, 6:14 AM
    📣 📣📣 Hi everyone! Lots of you have recently mentioned multiple issues connected to the growth of our Slack community. We’ve formulated a change proposal to address these issues. We’re planning to update our community guidelines and introduce moderation. Please read this document for more information, and share your feedback with us in the designated thread in the #meta channel. We also want to make a call for moderators! Would you like to volunteer and make this community a helpful and welcoming place for everyone? 🙂 Please apply and share your feedback before July 20. 📣📣📣
    👍🏼 3
    👍 17
    k
    h
    +10
    • 13
    • 41
  • w

    William Reed

    07/02/2021, 1:29 PM
    what’s the proper way to escape a regular expression in intellij? I have my regex written out - can I just paste it when my cursor is in a quote block (
    "<cursor>"
    ) and it escapes properly?
    r
    e
    +2
    • 5
    • 31
  • l

    LlamaLad7

    07/02/2021, 9:05 PM
    Hi, I was wondering if there was any reason Kotlin/JVM seems not to use LambdaMetaFactory when creating lambda objects by default, instead opting to make a new class for every single lambda? Also, is there any way I can tell it to use LMF? Thanks
    d
    s
    e
    • 4
    • 12
Powered by Linen
Title
l

LlamaLad7

07/02/2021, 9:05 PM
Hi, I was wondering if there was any reason Kotlin/JVM seems not to use LambdaMetaFactory when creating lambda objects by default, instead opting to make a new class for every single lambda? Also, is there any way I can tell it to use LMF? Thanks
d

diesieben07

07/02/2021, 9:09 PM
https://kotlinlang.org/docs/whatsnew15.html#lambdas-via-invokedynamic
l

LlamaLad7

07/02/2021, 9:09 PM
Ahh it's opt-in at the moment
thanks so much
d

diesieben07

07/02/2021, 9:10 PM
Yes and the reasons are explained there as well
l

LlamaLad7

07/02/2021, 9:10 PM
Great, thank you!
s

Sourabh Rawat

07/02/2021, 9:15 PM
A lambda compiled into invokedynamic is not serializable
So normally, you can serialize lamdas and store in database?
d

diesieben07

07/02/2021, 9:29 PM
Yes,
kotlin.jvm.internal.Lambda
(the base class for lambdas generated by the compiler on the JVM) implements
java.io.Serializable
, so it can be serialized using the Java serialization mechanism - provided any captured variables are also serializable.
You probably should never do that though!
e

ephemient

07/02/2021, 10:14 PM
serializing lambdas is questionable, but serializable method references (e.g.
String::isEmpty
) could be considered reasonable
(Java 8 doesn't support serializing either, but as the linked YouTrack issue mentions, changing Kotlin's behavior is a compatibility break, although hopefully one that doesn't affect many users)
d

diesieben07

07/04/2021, 8:48 AM
Java 8 definitely has serializable lambdas. Brian Goetz and colleagues lost many a hair over that if their talks are to trust 🙂
https://docs.oracle.com/javase/8/docs/api/java/lang/invoke/SerializedLambda.html
View count: 6