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

    Tom Pratt

    12/29/2020, 6:03 PM
    I wonder if anyone can help me to add a cocoapod to a kotlin native module, not having much luck so far! The library is Google's NearbyMessages API. https://developers.google.com/nearby/messages/ios/get-started So far I have: 1. Cloned the KMM with cocoapods sample app. https://github.com/Kotlin/kotlin-with-cocoapods-sample 2. Gradle sync and build the project. Everything succeeds. 3. Add the NearbyMessages pod in build.gradle.kts just above the AFNetworking line...
    pod("NearbyMessages")
    4. Now when I gradle sync I get the following error.
    > Task :kotlin-library:cinteropNearbyMessagesIosArm64 FAILED
    Exception in thread "main" java.lang.Error: /var/folders/t7/gwvnk41x66g5kmr7s7y8thdw0000gn/T/6648793494349780018.m:1:9: fatal error: module 'NearbyMessages' not found
    at org.jetbrains.kotlin.native.interop.indexer.UtilsKt.ensureNoCompileErrors(Utils.kt:152)
    at org.jetbrains.kotlin.native.interop.indexer.ModuleSupportKt.getModulesASTFiles(ModuleSupport.kt:68)
    at org.jetbrains.kotlin.native.interop.indexer.ModuleSupportKt.getModulesInfo(ModuleSupport.kt:14)
    at org.jetbrains.kotlin.native.interop.gen.jvm.MainKt.buildNativeLibrary(main.kt:507)
    at org.jetbrains.kotlin.native.interop.gen.jvm.MainKt.processCLib(main.kt:265)
    at org.jetbrains.kotlin.native.interop.gen.jvm.MainKt.interop(main.kt:73)
    at org.jetbrains.kotlin.cli.utilities.InteropCompilerKt.invokeInterop(InteropCompiler.kt:45)
    at org.jetbrains.kotlin.cli.utilities.MainKt.mainImpl(main.kt:19)
    at org.jetbrains.kotlin.cli.utilities.MainKt.main(main.kt:41)
    Execution failed for task ':kotlin-library:cinteropNearbyMessagesIosArm64'.
    > Process 'command '/Applications/Android <http://Studio.app/Contents/jre/jdk/Contents/Home/bin/java|Studio.app/Contents/jre/jdk/Contents/Home/bin/java>'' finished with non-zero exit value 1
    I was able to install the cocoapod using a podfile and
    pod install
    . With no KMM involved. I've tried all sorts of random stuff besides but these are the steps that seem like they should work.
    m
    • 2
    • 7
  • e

    eygraber

    12/30/2020, 3:46 AM
    Is it possible to create an infix function scoped to a specific class? Something like:
    // Foo is a library class and out of my control
    class Foo
    
    infix fun Foo.togetherWith(first: Any, second: Any) = ...
    
    inline fun fooBuilder(builder: Foo.() -> Unit) {
      Foo().apply(builder)
    }
    
    fooBuilder {
      1 togetherWith 2
    }
    I know this specifically doesn't work, but is there any way to achieve this behavior?
    n
    a
    b
    • 4
    • 37
  • s

    sbeve

    12/30/2020, 5:12 AM
    still dont understand what Ktor is even after reading a few articles
    a
    • 2
    • 1
  • a

    Animesh Sahu

    12/30/2020, 5:35 AM
    Is there a setting to disable continuation indents here, I found no options in Intellij Code style.
    • 1
    • 1
  • a

    andylamax

    12/30/2020, 6:44 AM
    Hi, is there a way to disable automatic destructures that the compiler autogenerate for data classes?
    c
    v
    • 3
    • 4
  • e

    Eugen Martynov

    12/30/2020, 7:43 AM
    No #generics channel?
    v
    • 2
    • 1
  • e

    Eugen Martynov

    12/30/2020, 7:48 AM
    I’m looking if it is possible to use reified for class instantiation. I tried code like:
    class BaseFragment<T: BaseViewModel> {
      val viewModel: T = createViewModel()
    }
    
    private fun <reified T: BaseViewModel> createViewModel() = T::java.class.newInstance()
    This compiles but I have just one function with BaseViewModel class as argument. Is it possible to get many such methods for every class that extends it with more specific view model?
    f
    • 2
    • 3
  • j

    Jukka Siivonen

    12/30/2020, 8:49 AM
    Any suggestions for following problem, let's say I have a simple type which is used in two different projects A and B (modules). Now I need to make this same type behave different in module B. Code example:
    h
    • 2
    • 7
  • z

    ziv kesten

    12/30/2020, 9:38 AM
    How can i avoid long transformation functions when trying to map elements of flow?
    override suspend fun observeWatchedShows(): Flow<List<Show>> {
        return watchListDao.observeShows()
            //Map flow of list of Watched Shows to flow of list of Show
            .map { listOfShows ->
                entityMapper.toDomainList(
                    //Map list of WatchShows to list of ShowEntity
                    listOfShows.map { watchedShow -> watchedShow.show }
                )
            }
    
        // Mapping Flow<List<WatchedShow>> -> Flow<List<ShowEntity>> -> Flow<List<Show>>
    }
    d
    a
    • 3
    • 21
  • a

    Animesh Sahu

    12/30/2020, 11:18 AM
    This is not getting anywhere, tried changing Xmx in gradle.properites file 😞
    a
    • 2
    • 5
  • é

    Édgar Sánchez Gordón

    12/30/2020, 5:51 PM
    What's the current suggestion for an ORM library? I lean towards something Kotlin-idiomatic, and I also kind of prefer light ORM's, OTOH I appreciate popularity and future-proofness (I know, I know, nothing is really future-proof, but still). Within these kind of loose constraints, all suggestions welcomed! (and thanks in advance, of course)
    h
    r
    +5
    • 8
    • 9
  • d

    df

    12/31/2020, 2:05 PM
    Hey there. I have following code
    private suspend fun upsertAssets(code: String, assets: List<CreateAssetCommand>): List<UpsertAssetResponse> {
            return assets.chunked(100)
                .map { akeneoClient.upsertAssets(code, it) }
                .fold(mutableListOf()) { acc, next -> acc + next }
        }
    that produces the compile time error
    Type mismatch: inferred type is List<UpsertAssetResponse> but MutableList<UpsertAssetResponse> was expected
    (the fold line). What am I missing?
    d
    t
    j
    • 4
    • 10
  • c

    Ch8n

    01/03/2021, 6:16 AM
    Hello, world.KT! I'm looking for some Kotlin orientated game engine for building 2D games. Is there any resource? I would be exporting games to web or android
    a
    n
    a
    • 4
    • 3
  • t

    Timo Gruen

    01/03/2021, 11:14 AM
    Heyho, I stumbled across visibility issues of
    private val
    variables.
    class Client(private val delegate: InternalClient)
    - The compiler tells me , that i’m not allowed to use
    InternalClient
    as
    val
    because of it’s being exposed public. But… the private should limit the visibility to other classes so no getter and no setter should be present, and it shouldn’t make any difference from compiler perspective, since no user is ever allowed to invoke
    delegate
    directly via
    client
    . Or am i missing something here?
    g
    • 2
    • 2
  • j

    James Richardson

    01/03/2021, 3:34 PM
    I had a question regarding performance. I hadn't previously noticed that a field access in kotlin seems to be always via an accessor method. For example a public field Bob.t referenced as b.t in some file will invokevirtual Bob.getT which returns getfield Bob.t - in the case where t is got a lot this can affect performance quite a bit. Turning a data class from kotlin to a simple java object with final immutable fields changes this to getfield and so saves the indirection. Is there a way to prefer field access?
    j
    t
    +4
    • 7
    • 15
  • l

    liminal

    01/03/2021, 6:32 PM
    I have 2 lists holding the same data type that has unique “id” property. One is a bigger list that serves as a single source of truth and the other is a sublist. After the big list gets updated, how can I go through the smaller list and update values present there from the bigger list when “id” matches?
    j
    • 2
    • 2
  • k

    kenkyee

    01/04/2021, 2:05 AM
    #coroutines?
    j
    g
    • 3
    • 2
  • z

    zak.taccardi

    01/04/2021, 10:05 PM
    Is it possible to return early from an exhaustive
    when
    ?
    s
    f
    +3
    • 6
    • 20
  • s

    Slackbot

    01/05/2021, 7:45 AM
    This message was deleted.
    n
    d
    • 3
    • 3
  • r

    Rachid

    01/05/2021, 7:21 PM
    For a Spring Boot app we want to add some extra meta data to particular fields in the JSON response. Since this is a "cross cutting" concern in our project we want to make this as simple/concise as possible. We made a proof of concept with annotations. So we created 2 annotations and used reflection to generate the metadata based on the annotated fields. An example to use this is:
    data class Response(
        val id: Int,
        @MyFirstMetadata
        val label: LabelResponse
    )
    The idea that for the field
    label
    we generate some metadata and add this as extra fields in
    LabelResponse
    . I wonder if there's a way to reach our goal without annotations and reflection. I read about making DSL's in Kotlin, but I couldn't directly find something for our situation. I'm happy to hear your thoughts.
    s
    n
    • 3
    • 4
  • c

    Chills

    01/06/2021, 9:32 AM
    Why this (stream) is not possible in Kotlin , also why do we have different syntax for
    for-loop
    https://pastebin.com/K1uQx2mL
    sophia.likedPeople.stream().forEach(x->println(x.name))
    g
    f
    • 3
    • 14
  • f

    frogger

    01/06/2021, 11:08 AM
    Is there a suggested approach for “an equals method for an interface”? I.e. not checking two actual objects for equality based on their implementing classes but only checking those fields/functions for equality that are declared in interface?
    i
    • 2
    • 1
  • i

    igor.wojda

    01/06/2021, 11:44 AM
    Is there any case where this could be valid? (having
    val
    , not
    var
    with nullable type and no custom getter). Do you think we need IDE warning here?
    private val requestId: String? = null
    d
    j
    y
    • 4
    • 3
  • a

    Alex

    01/06/2021, 1:30 PM
    registry.addConverter(
                object : Converter<String, IaaSProvider> {
                    override fun convert(source: String): IaaSProvider = IaaSProvider.fromString(source)
                }
            )
    Converter is a SAM interface, So technically it would be possible to do something like this:
    registry.addConverter { source -> IaaSProvider.fromString(source) }
    But how would I define generics in this lambda?
    j
    • 2
    • 10
  • r

    ribesg

    01/06/2021, 5:11 PM
    So uh I have some old code that I’m trying to update to Kotlin 1.4 and it stopped working. Here is a reproducer https://pl.kotl.in/GGe3tNnwm (try changing the Kotlin version from <1.4 to 1.4+ to see different results) I fear it was actually using a bug that was fixed. Any idea of how I should transform this code to achieve the same behavior as before?
    n
    b
    y
    • 4
    • 9
  • s

    spnda

    01/07/2021, 10:46 PM
    Can one write a when statement and check if a list contains a value? Like the following (pseudocode):
    when {
        array.contains(value) -> {
    
        }
    }
    :yes-black: 1
    n
    v
    • 3
    • 7
  • e

    Emery Tanghanwaye

    01/07/2021, 11:32 PM
    hey all, does kotlin have any good networking libraries?
    z
    c
    m
    • 4
    • 4
  • e

    Emery Tanghanwaye

    01/07/2021, 11:32 PM
    looking to mess around with p2p networking
    e
    • 2
    • 1
  • t

    Tim Malseed

    01/08/2021, 1:11 AM
    Is there a neater way to do this?
    y
    • 2
    • 6
  • s

    string randomizer

    01/08/2021, 11:40 AM
    hello when you read https://github.com/JetBrains/kotlin-web-site/blob/master/README.md you will see that the kotlin slack badge isn't shown in the readme cause http://slack.kotlinlang.org/badge.svg redirects to a missing badge .svg cause http://slack.kotlinlang.org redirects to a survey page(https://surveys.jetbrains.com/s3/kotlin-slack-sign-up) no matter which HTTP request you do...
    v
    • 2
    • 3
Powered by Linen
Title
s

string randomizer

01/08/2021, 11:40 AM
hello when you read https://github.com/JetBrains/kotlin-web-site/blob/master/README.md you will see that the kotlin slack badge isn't shown in the readme cause http://slack.kotlinlang.org/badge.svg redirects to a missing badge .svg cause http://slack.kotlinlang.org redirects to a survey page(https://surveys.jetbrains.com/s3/kotlin-slack-sign-up) no matter which HTTP request you do...
v

Vampire

01/08/2021, 12:53 PM
You should open an issue on youtrack.jetbrains.com
s

string randomizer

01/11/2021, 9:56 PM
https://youtrack.jetbrains.com/issue/KT-40720 there is already a bug filed for this in july 2020
v

Vampire

01/11/2021, 9:58 PM
Great, I voted
View count: 2