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

    Dajuan Mcdonald

    12/23/2022, 5:59 PM
    👋 Hello, team!
  • n

    Nat Strangerweather

    12/26/2022, 5:54 PM
    Hi, I am a bit confused about Kotlin Coroutines Jobs. Is it the case that a job can only run once? I wanted to launch the
    searchJob
    every time my search parameter changed in the example below. What happens is that the
    searchJob
    is called successfully the first time I pass my parameter, but never again after that. Could someone please have a look ?
    j
    b
    • 3
    • 28
  • a

    Ayfri

    12/26/2022, 9:22 PM
    What Physics Engine could I use with Processing 4 ? I've seen that there are multiple Physics Engine in Java, very few in Kotlin, I've stamble uppon KPhysics which seems nice but is there anything else for the language ?
    k
    a
    • 3
    • 5
  • s

    Sam Stone

    12/26/2022, 10:56 PM
    How do I get the string that was passed to the command line to start the JVM?
    v
    s
    • 3
    • 5
  • m

    Minh Knitsch

    12/27/2022, 2:42 PM
    Hey 👋 Is there a way to test/assert logged messages (type DEBUG, message content)? Using "import mu.KotlinLogging" 👀
  • l

    Luis Mirabal

    12/28/2022, 3:52 PM
    I don't think you can do that in kotlin or java. But it looks like you could use expression language: https://stackoverflow.com/questions/54038928/how-to-pass-dynamic-topic-name-to-kafkalistenertopics-from-environment-variab
    b
    a
    j
    • 4
    • 18
  • a

    Alexandre A Barbosa

    12/28/2022, 8:40 PM
    hey channel. I’ve worked with Spring Open Feign with Java but know I want to do the same with Kotlin. Please, is there someone here with a good boilerplate? I mean.. without this kind of issue.
  • a

    asavio

    12/29/2022, 10:35 AM
    Hey Channel! How does one convert a Map<String, Any?> to data class? I’m trying to convert a
    Map<String, Any?>
    to a data class object using Kotlinx Serialisation. The Data Classes:
    import kotlinx.serialization.Serializable
    
    @Serializable
    data class Person(
        val uuid: String,
        val age: Int,
        val name: String,
        val address: Address
    )
    
    @Serializable
    data class Address(
        val street: String,
        val city: String,
        val zip: Int
    )
    This is the function I use to convert to data class.
    import kotlinx.serialization.json.decodeFromJsonElement
    import kotlinx.serialization.json.encodeToJsonElement
    import kotlinx.serialization.json.jsonObject
    import kotlinx.serialization.json.Json
    
    internal inline fun <reified T : Any> Map<String, Any?>.toPojo(): T {
        val JSON = Json { encodeDefaults = true }
        val jsonObject = JSON.encodeToJsonElement(this).jsonObject
        return JSON.decodeFromJsonElement<T>(jsonObject)
    }
    Here’s the function call:
    val map = mapOf(
        "uuid" to "agsdjhdg",
        "age" to 26,
        "name" to "Aseem",
        "address" to mapOf(
            "city" to "Chennai",
            "street" to "street1"
        )
    )
    
    println(map.toPojo<Person>())
    I get the following error:
    Exception in thread "main" kotlinx.serialization.SerializationException: Serializer for class 'Any' is not found.
    Mark the class as @Serializable or provide the serializer explicitly.
    	at kotlinx.serialization.internal.Platform_commonKt.serializerNotRegistered(Platform.common.kt:91)
    	at kotlinx.serialization.internal.PlatformKt.platformSpecificSerializerNotRegistered(Platform.kt:29)
    	at kotlinx.serialization.SerializersKt__SerializersKt.serializer(Serializers.kt:60)
    	at kotlinx.serialization.SerializersKt.serializer(Unknown Source)
    	at kotlinx.serialization.SerializersKt__SerializersKt.serializersForParameters(Serializers.kt:117)
    	at kotlinx.serialization.SerializersKt.serializersForParameters(Unknown Source)
    	at kotlinx.serialization.SerializersKt__SerializersKt.serializerByKTypeImpl$SerializersKt__SerializersKt(Serializers.kt:99)
    	at kotlinx.serialization.SerializersKt__SerializersKt.serializer(Serializers.kt:59)
    	at kotlinx.serialization.SerializersKt.serializer(Unknown Source)
    	at MainKt.main(Main.kt:98)
    How does one convert a Map<String, Any?> to data class? Thanks in advance!
    c
    a
    • 3
    • 22
  • r

    Robert Jaros

    12/29/2022, 4:43 PM
    Still no blog post about 1.8.0 release?
    t
    d
    +2
    • 5
    • 4
  • a

    Aminu Babayo Shehu

    12/29/2022, 6:47 PM
    Hello, please help, I deployed ktor project to docker using this
    Dockerfile
    but when I try to upload image and read file I’m getting error of
    file or directory not found
    BUT in reality the directory exist or file do exist
    c
    • 2
    • 13
  • e

    ephemient

    12/29/2022, 10:03 PM
    in theory, there could be some unique advantages to
    LinkedList
    . however, by conforming to the
    List
    interface, none of those are realized in Java at all
    c
    c
    +7
    • 10
    • 51
  • m

    mcpiroman

    12/30/2022, 3:58 PM
    I guess there wasn't, but maybe it is possible now? For me I'd like to suppress `MayBeConstant`and use only `val`s
    e
    • 2
    • 1
  • l

    Landry Norris

    12/30/2022, 5:56 PM
    What happens if you move the list declarations above the enum declaration?
    s
    • 2
    • 1
  • p

    poohbar

    12/30/2022, 6:32 PM
    Easy question. There is
    .forEach()
    on
    Iterator
    but not
    .map()
    . What is the right way to map over an iterator?
    • 1
    • 1
  • d

    Devan Lai

    12/30/2022, 11:56 PM
    I've got a somewhat unusual use case that I'd appreciate any input on. I've got an Android app storing data in SQLite using Android's Room persistence library, but for troubleshooting purposes, I have a system to export the database file so that I can look at it on my desktop and do analysis on the contents. Room is an Android-specific thing, so I can't reuse any of the Room data modelling for a pure JVM program running on the desktop. Ideally I'd really just like to run some basic SQL queries on the database without modifying it. Really just the type-safe equivalent of firing up the sqlite client and running some queries. Can I do that without too much effort if I use an ORM-focused library like SQLDelight or Ktorm, or would I have to model everything in the ORM to make that work? (There are also some migrations between versions, mostly in tables I'm not interested in, and I'd prefer to not have to create those if I can avoid it)
  • d

    df

    12/31/2022, 11:49 AM
    Hi Folks. I have a maven multi-module project and all of them are Kotlin. Now I want to use Lombok in one of the modules to make the module easier to use in another java project. I already read this https://kotlinlang.org/docs/lombok.html and followed the steps, but the compiled classes don’t contain the generated code from Lombok.
    mvn clean package
    output, Kotlin file and generated class file, as well as the pom file, can be found here https://gist.github.com/dfreudenberger/33ceedf370757c7a380c8fd8f4fc8145. Any help is highly appreciated 🙂
    t
    e
    d
    • 4
    • 8
  • o

    oday

    01/02/2023, 12:38 PM
    if I’m doing:
    when (string){
    
        "SomeString" -> { }
    }
    can i have it somewhere set to ignore case when matching?
    n
    s
    +2
    • 5
    • 20
  • s

    Sam Stone

    01/02/2023, 8:14 PM
    Correct me if I am wrong: the Kotlin compiler was originally written in Java. Meaning, a Java program
    J
    was written to parse the AST of a KT file(s) (the first Kotlin compiler, written in Java) and produce an executable/binary. Program
    J
    was then used to compile a Kotlin program
    K
    that itself could read KT files (the second Kotlin compiler, written in Kotlin) and produce a binary.
    K
    was used to compile an iteratively better version
    K1
    , which was used to compile
    K2
    , etc. Does the current compiler rely on the JVM to run?
    h
    d
    +2
    • 5
    • 4
  • t

    Tech

    01/03/2023, 1:59 AM
    Hey I was wondering if it was possible to put properties on a class via annotation? Example being
    annotation class Example(val a: String)
    
    @Example("t")
    class Foo() 
    // to
    @Example("t")
    class Foo(val: a = "t")
    a
    j
    s
    • 4
    • 7
  • n

    nkiesel

    01/03/2023, 5:06 AM
    I have a question regrading `Grouping.fold`: I assumed the following 2 calls to return the same value, but the second returns
    {a=[1, 3, 4, 5], b=[1, 3, 4, 5]}
    instead of the expected
    {a=[1, 3, 5], b=[4]}
    . Looks the 2nd variant re-uses the initial value for all groups. What is a good use case for the 2nd variant?
    val g = listOf("a" to listOf(1, 3), "b" to listOf(4), "a" to listOf(5)).groupingBy { it.first }
    g.fold({ _, _ -> mutableListOf<Int>() }, { _, acc, item -> acc.addAll(item.second); acc })
    g.fold(mutableListOf<Int>(), { acc, item -> acc.addAll(item.second); acc })
    r
    • 2
    • 1
  • y

    y

    01/03/2023, 12:39 PM
    is
    return@
    considered harmful or unidiomatic? for example, I want to make a function that sums up the number of values of a list, or returns
    null
    if a certain value is detected. I wrote it as
    fun List<Foo>.calcSum() = this.fold(0) { sum, val -> if (something) { sum + val } else { return@calcSum null } }
    is this bad style?
    v
    j
    +3
    • 6
    • 15
  • d

    df

    01/03/2023, 2:57 PM
    @Component
    class YourConsumer(
        private val client: MyFeignClient
    ) {
    ...
    }
    a
    j
    • 3
    • 9
  • y

    y

    01/04/2023, 4:52 AM
    is there any way to express this
    plus
    overload with Kotlin pattern matching?
    private sealed class ValueCount {
            data class A(val amount: Int) : ValueCount()
            object B : ValueCount()
    
            operator fun plus(rhs: ValueCount) =
                when (this to rhs) {
                    (A, B), (B, A) -> { B }
                    (A, A) -> { A(this.amount + rhs.amount) }
                }
        }
    note, I’m aware that I can turn this into an
    if
    /`else` :
    operator fun plus(rhs: ValueCount) =
        if (this is B || rhs is B) {
            B
        } else {
            val lhsAmount = (this as A).amount
            val rhsAmount = (rhs as A).amount
            A(lhsAmount + rhsAmount)
        }
    e
    • 2
    • 7
  • a

    ank

    01/04/2023, 5:23 AM
    When a suspend function calls another, is there an assurance of the order of operations and whether they are synchronous or not? Will this always print A-B-C regardless of under which conditions x is invoked?
    suspend fun x() {
      print("A")
      y()
      print("B")
    }
    suspend fun y() {
      print("C")
    }
    e
    p
    • 3
    • 11
  • u

    Ubed

    01/04/2023, 1:05 PM
    has anyone worked on login using google and able to generate jwt tokens after successful login?
  • m

    Matti Viljamaa

    01/04/2023, 3:51 PM
    Hey I am really interested in studying the source code, but I am finding it very laborious to grasp what's going on by just reading the source at https://github.com/JetBrains/kotlin . I can understand the concepts related the what's happening like IRs, parsing, ..., but I don't grasp the folder structures, filenames and ideas regarding encapsulation.
    d
    • 2
    • 9
  • d

    dave08

    01/04/2023, 4:05 PM
    What's the nicest way to take two lists, one of
    data class Foo(val id: String, ...)
    and one of
    data class Baz(val id: String, ...)
    and output a map of the id against a pair of Foo and Baz that correspond
    Map<String, Pair<Foo?, Baz?>>
    where either could not exist?
    l
    s
    e
    • 4
    • 27
  • m

    Matti Viljamaa

    01/04/2023, 5:55 PM
    BTW do you know how serious Google's push of Kotlin to Android is?
    j
    l
    +4
    • 7
    • 148
  • m

    Matti Viljamaa

    01/04/2023, 5:56 PM
    To me it seemed like Java is being depreceated totally, but is it this way or dual APIs?
  • l

    Landry Norris

    01/04/2023, 7:17 PM
    Is there a way to check if a lazy variable has been initialized? Some sort of equivalent to lateinit’s
    ::something.isInitialized
    ?
    k
    v
    • 3
    • 4
Powered by Linen
Title
l

Landry Norris

01/04/2023, 7:17 PM
Is there a way to check if a lazy variable has been initialized? Some sort of equivalent to lateinit’s
::something.isInitialized
?
k

Kirill Grouchnikov

01/04/2023, 7:19 PM
https://www.google.com/search?client=firefox-b-1-d&amp;q=kotlin+check+if+lazy+is+initialized
Top two answers are your friends
l

Landry Norris

01/04/2023, 7:23 PM
It’s interesting that it needs to change the access level. Does this work in Multiplatform?
v

Vampire

01/04/2023, 10:26 PM
Top two answers are your friends
Be careful with such statements, Google result lists are personalized. :-)
View count: 11