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

    Tresa

    01/21/2021, 1:37 PM
    When we have a KMM module A and a development POD called B which is dependent on A, B builds fine and pod install happens fine. If There's a module C, who has dependency to B via pod, then we get error:" target has transitive dependencies that include statically linked binaries:", while pod update. To fix this if we comment out use_frameworks! or remove it from podfile of C, pod install happens fine but build fails with could not find module SQLCipher, SQLCipher is depended by A via the cocoapods plugin in gradle. If we use another solution for transitive dependency as follows
    pre_install do |installer|
    Pod::Installer::Xcode::TargetValidator.send(:define_method, :verify_no_static_framework_transitive_dependencies) {}
    end
    we end up with other errors during build like Undefined symbols for architecture x86_64: "_sqlite3_bind_text16", referenced from: _SQLiter_SQLiteStatement_nativeBindString in ConnectPlusSharedDB(result.o)
    n
    • 2
    • 3
  • a

    Afzal Najam

    01/21/2021, 4:47 PM
    Are namespaces coming to Kotlin (on JVM) soon? 😛
    m
    n
    +4
    • 7
    • 96
  • m

    Mati Galli

    01/21/2021, 7:41 PM
    Hi guys! 🙂 There is a way to serialize with
    @Serializable
    a
    java.util.Date
    with this format
    2018-11-14T13:25:30Z
    ? I´m using Ktor and
    kotlinx.serialization
    s
    p
    • 3
    • 4
  • p

    Philipp Mayer

    01/21/2021, 9:26 PM
    Hi, can one accomplish this
    flowNodes.forEach { initialNode ->
            initialNode.succeedingNodes.list().forEach { nextNode ->
                graph.addArc(initialNode to nextNode)
            }
        }
    in a more fluent way? Seems like I'm missing something. The use case would be the following: I have an initial Node 1 with the succeeding nodes 2 and 3. The target is to add 1 to 2 and 1 to 3 to the graph. thanks a lot!
    j
    p
    • 3
    • 9
  • i

    Ifvwm

    01/22/2021, 9:33 AM
    how to wait for coroutine in non-suspend function?
    fun f () {
      val result = async { ktor-client-function... return@async 1 }
      return result
    }
    a
    a
    • 3
    • 16
  • b

    bod

    01/22/2021, 3:01 PM
    Hello, World! A generics question that lets me perplexed 🤔!
    fun <T> foo(a: T, block: () -> T) {}
    foo("Hello") { 1 }
    How come this compiles?
    T
    is
    String
    for
    a
    but
    Int
    for the
    block
    lambda. Bonus question: what's a way to make this not compile and enforce the same type? 🙂 Thanks 🙏
    d
    n
    +4
    • 7
    • 51
  • p

    Pablo

    01/22/2021, 3:29 PM
    What's the idiomatic way to : if I have a listOf<String>(...) and then I map it to a listOf<MyUiClass> to once I have this listOf<MyUiClass> remove an item of it if let's say today == whatever. Pseudo : val myList = listOf<String>("example1","example2",...) val mappedUiClass = myList.map{myMapper.map(it)} //Here I'd like to remove one exactly item if a condition is true. So for instance if mappedUiClass contains {id=1,name="Jhon", type: "MyType1"} {id=2,name="Hual", type: "MyType2"} {id=3,name="Hjdu", type: "MyType3"} If the condition is true I just want to keep in mappedUiClass the id1 and id3, so if condition == true remove MyType2.
    d
    • 2
    • 31
  • j

    Junior leoncio

    01/22/2021, 4:41 PM
    hello guys, i'm creating a quiz app, i'm having trouble translating the questions i get from the open trivia database to my app, i want to translate from english to portuguese! Can someone help me?
    :stackoverflow: 1
    :google: 3
    u
    • 2
    • 3
  • a

    Animesh Sahu

    01/22/2021, 5:40 PM
    Not really a kotlin question, but rather a gradle. How should we check if option like
    --info
    or
    --verbose
    is passed within a task 👀 when creating the task :blob-thinking-upside-down:
    r
    v
    • 3
    • 9
  • y

    Youssef Shoaib [MOD]

    01/22/2021, 10:07 PM
    Does anyone know if code like the following:
    inline fun <T> identity(block: () -> T) = block
    inline fun <T> do(block: () -> T): T = block()
    fun main() {
        println(do(identity { "hello" })
    }
    would be optimised to basically the equivalent of this:
    fun main () {
        println("hello")
    }
    Or would the lambda object still be created because it is being returned by
    identity
    ? I don't have access to an IDE right this second but this question is burning me so thought I'd ask. If anyone has the time, try pasting this code into a kotlin project then doing
    Show Kotlin Bytecode
    then
    Decompile
    and look at the Java source code to see what happens.
    n
    • 2
    • 7
  • a

    Andrew

    01/23/2021, 6:01 AM
    In kotlin is there a way to give an interface to a class you don't own? I'm trying to reimplement a class from another library and want a shared contract between mine and that one as an intermediary until I'm finished.
    c
    j
    +4
    • 7
    • 7
  • m

    Mjahangiry75

    01/23/2021, 1:39 PM
    as Coroutine's document says: "The main difference is that the runBlocking method blocks the current thread for waiting, while coroutineScope just suspends, releasing the underlying thread for other usages." and the code below works as it expected:
    fun main() = runBlocking { // this: CoroutineScope
        launch { 
            delay(200L)
            println("Task from runBlocking")
        }
        
        coroutineScope { // Creates a coroutine scope
            launch {
                delay(500L) 
                println("Task from nested launch")
            }
        
            delay(100L)
            println("Task from coroutine scope") // This line will be printed before the nested launch
        }
        
        println("Coroutine scope is over") // This line is not printed until the nested launch completes
    }
    I made a change to see the difference, I changed the
    coroutineScope
    to
    runBlocking
    and then as the document said
    runBlocking
    blocks the current thread and
    coroutineScope
    suspends but I got the same output. does anybody know why?
    k
    • 2
    • 2
  • e

    elect

    01/23/2021, 8:45 PM
    I need to retrieve recursively the list of
    .java
    files given a root folder to redirect to
    javac
    . Isn't there a nicer kotlin alternative to this?
    val sources = Files.find(Paths.get(srcDir), 999, { path, attr ->
                attr.isRegularFile && path.toString().endsWith(".java")
            }).map { it.toString() }.collect(Collectors.joining(" "))
    Files.find
    returns a
    Stream<Path!>!
    and I need to go trough
    map
    +
    collect
    +
    Collectors
    instead something more concise
    d
    r
    • 3
    • 3
  • n

    Nir

    01/23/2021, 10:05 PM
    In some cases this lack can cause repeated code and work in later applying fold etc to the Grouping
    i
    • 2
    • 11
  • f

    Fred Ells

    01/23/2021, 10:05 PM
    👋 Hey. Looking for some help. I am writing a game using kotlin native and KorGE. All my items classes are generated and extend the sealed class
    Item
    . This results in a kotlin file ~14k lines long. And Intellij IDEA simply cannot handle the file. It essentially freezes instantly as long as the file exists in the project. Any ideas on how to deal with this situation?
    r
    y
    c
    • 4
    • 7
  • n

    napperley

    01/23/2021, 11:28 PM
    If you want to see Kotlin as an option for Embedded development (and as a high priority item on the Kotlin Roadmap - https://kotlinlang.org/roadmap.html ) then please vote for this issue: https://youtrack.jetbrains.com/issue/KT-44498
    n
    a
    m
    • 4
    • 22
  • c

    christophsturm

    01/24/2021, 10:12 PM
    when i build a kotlin project, are resources from main/kotlin and test/kotlin not copied to the classes directory? i want to load json files in my unit tests with
    javaClass.getResource("myJsonFile.json")
    but it does not work.
    v
    e
    n
    • 4
    • 30
  • m

    Mikołaj Kąkol

    01/25/2021, 10:14 AM
    hi, is it possible to tel IDE that this unused method is part of API that this library provides? so I won’t get unwanted warnings?
    m
    c
    a
    • 4
    • 5
  • a

    Animesh Sahu

    01/25/2021, 11:54 AM
    Hmm, I thought
    String.trimIndent()
    was a runtime function, but according to the the latest safari video up at 2:00 he says its compile time transformation, but then I tried to use it in a
    const val
    then it says
    Const 'val' initializer should be a constant value
    is it evaluated at run-time or at compile-time just not able to fit into
    const val
    (maybe because compiler can't figure it out easily)?
    m
    • 2
    • 2
  • s

    stephanmg

    01/25/2021, 1:51 PM
    Hello, anybody knows how to introduce newlines in KDoc? I am using Dokka (using the Jekyll output for GH pages) to generate my documentation. What I tried: “\” at line end, empty lines and <br>. Did not work for me.
    m
    • 2
    • 3
  • d

    dasralph

    01/25/2021, 2:36 PM
    I’m developing a Kotlin multiplatform project. On my mac, everything works fine, but our iOS developer runs into trouble 😞 He gets this error
    The Kotlin/Native distribution used in this build does not provide the standard library.
    Does anyone have an idea whats going wrong?
    m
    k
    +2
    • 5
    • 5
  • k

    Kirill Grouchnikov

    01/25/2021, 7:32 PM
    Why negative reactions? Eclipse has a very strong presence in a variety of "enterprise" settings, for both backend and frontend development. Supporting Kotlin as a first class citizen in that ecosystem should be viewed as a positive.
    n
    • 2
    • 5
  • a

    Andrew

    01/26/2021, 5:02 AM
    class MyObject(private val a: Int, private val b: Double) {
    	constructor(str: String) : this(parse(str))
    	companion object {
    		private fun parse(str: String): ???
    	}
    }
    Is there anything that would allow this to work? Currently I have to create 2 parse functions, one to get the first and another for the second value I need.
    n
    e
    • 3
    • 6
  • r

    Radoslaw Juszczyk

    01/26/2021, 10:42 AM
    Anyone playing with kotlin-multiplatform and this library: com.russhwolf:multiplatform-settings ? In my project which I have just created: IntelliJ 2020.3 > File > New > Project… > Kotlin > Mobile Application I have added a dependency:
    val commonMain by getting {
       dependencies {
           implementation("com.russhwolf:multiplatform-settings:0.6.1")
       }
    }
    Inside iosMain I have added this code:
    fun test(d: NSUserDefaults) {
        AppleSettings(d)
    }
    And everything compiles correctly but IDE complains about AppleSettings that (Cannot access class ‘platform.Foundation.NSUserDefaults’. Check your module classpath for missing or conflicting dependencies) [see image below] any ideas what could be the reason of this error?
    r
    • 2
    • 2
  • y

    Yuri Drigin

    01/26/2021, 11:26 AM
    Hi folks! Has anyone experience with Jetpack Compose in real life app? We are starting refactoring old project and I want to try it. But Compose in alpha still. Is it safe?
    g
    • 2
    • 2
  • h

    Henrik Johansson

    01/26/2021, 2:39 PM
    Do I have to create serializers for Java types? For example UUID and Instant or is there some library available for it?
    s
    m
    • 3
    • 21
  • k

    Koenichiwa

    01/26/2021, 4:14 PM
    Hey guys👋 New here. I have a problem. I'm trying to find a software complexity measurement tool for Kotlin. Like pmccabe for c/c++ I was looking at detekt, but the website regarding this feature gives me a 404: https://detekt.github.io/complexity.html Does anyone know how to measure complexity with detekt? Or does anyone know of another available tool?
    c
    m
    • 3
    • 2
  • r

    Rainer Schlonvoigt

    01/27/2021, 8:58 AM
    is there a name for this syntax?
    myCollection
        .map { ... }
        .filter { ... }
        .forEach { ... }
    I know in Java i would call it “stream syntax” but that’s because there you actually need to create streams before being able to make these calls
    a
    m
    s
    • 4
    • 12
  • r

    Rainer Schlonvoigt

    01/27/2021, 9:25 AM
    Another discussion 😁 If you are in a situation where both
    Set<T>
    and
    List<T>
    are an option, which do you default to and why?
    c
    m
    m
    • 4
    • 9
  • c

    christophsturm

    01/27/2021, 11:34 AM
    why is there a
    kotlin.collections.LinkedHashSet
    typealias that aliases to
    java.util.LinkedHashSet
    (in typealiases.kt) , but also a kotlin class
    kotlin.collections.LinkedHashSet
    defined in
    LinkedHashSet.kt
    ?
    e
    • 2
    • 10
Powered by Linen
Title
c

christophsturm

01/27/2021, 11:34 AM
why is there a
kotlin.collections.LinkedHashSet
typealias that aliases to
java.util.LinkedHashSet
(in typealiases.kt) , but also a kotlin class
kotlin.collections.LinkedHashSet
defined in
LinkedHashSet.kt
?
e

ephemient

01/27/2021, 11:45 AM
are you aware of how `expect`/`actual` works in kotlin multiplatform? https://kotlinlang.org/docs/reference/mpp-connect-to-apis.html
libraries/stdlib/common/.../LinkedHashSet.kt:
expect class LinkedHashSet<E>
libraries/stdlib/jvm/src/kotlin/collections/TypeAliases.kt:
public actual typealias LinkedHashSet<E> = java.util.LinkedHashSet<E>
libraries/stdlib/wasm/src/kotlin/collections/LinkedHashSet.kt:
actual open class LinkedHashSet<E>
(ditto libraries/stdlib/js... etc)
this lets common code use LinkedHashSet; it will be replaced with the typealias on JVM and with a Kotlin implementation on other platforms
c

christophsturm

01/27/2021, 11:50 AM
ok so when idea navigates to the pure kotlin version in my jvm project thats an idea bug?
e

ephemient

01/27/2021, 11:51 AM
which one does it navigate to?
c

christophsturm

01/27/2021, 11:52 AM
the one in common
but not always, now it navigates to the alias
e

ephemient

01/27/2021, 11:53 AM
that would be correct, both common expect and jvm actual define what you can use on jvm
c

christophsturm

01/27/2021, 11:56 AM
ah ok it makes sense. I missed that the LinkedHashSet in common is just an expect
thanks for your explanation!
View count: 3