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

    Wxffel

    03/16/2023, 5:11 PM
    Hello, i am looking for help with Jetbrains Expose. We have two IdTables and a normal Table to set the IdTables in relation to another. But how do we create an entity in that third table?
    k
    • 2
    • 1
  • m

    Meika

    03/16/2023, 6:26 PM
    unsure whether this is the correct channel but need help to figuring out why I got
    ConcurrentModificationException
    when iterating (and modify) a mutable list. detail in thread 🧵
    r
    • 2
    • 5
  • t

    to-elixir

    03/17/2023, 1:19 AM
    Is it possible to get the C source code when compiled by kotlin native?
    p
    c
    l
    • 4
    • 6
  • s

    Sam Garfinkel

    03/17/2023, 1:21 AM
    If I wanted to define a Map where the value is some finite set of types, is there any way to properly type that union? My recollection of several years ago is that there was no way to properly define union types in Kotlin, just wondering if that’s changed?
    a
    p
    • 3
    • 3
  • m

    Maria Krishtal

    03/17/2023, 11:45 AM
    :kotlinnew:📣 We’re researching what’s important to developers who start using Kotlin and how we can support newcomers in their first steps. If you’ve been using Kotlin for less than a month, please share your experience with us during a short interview: https://kotl.in/o4z2mr All interviewees will receive a prize of their choice – a JetBrains All Products Pack subscription or an Amazon gift card! 🎁
  • t

    Tarun

    03/17/2023, 1:29 PM
    There is no gift card in INR !!!
    m
    • 2
    • 2
  • r

    Ruckus

    03/17/2023, 4:46 PM
    I have
    sealed class Bounds<in T : Comparable<T>> {
        abstract operator fun contains(value: T): Boolean
    }
    And I want
    object Unbounded : Bounds<Any?> {
        override fun contains(value: Any?) = true
    }
    However, I cannot as
    Any?
    violates the type bound. Is there a way to specify the type to make this work?
    s
    y
    m
    • 4
    • 13
  • j

    J

    03/18/2023, 2:48 AM
    I'm pretty new to Kotlin and have a few questions. Where is the most appropriate place to ask questions regarding problems I'm having with projects?
    a
    m
    • 3
    • 5
  • m

    Manasseh

    03/18/2023, 8:53 AM
    I noticed with Kotlin, documentation is either lean or non-existent. Is it just me?
    w
    m
    • 3
    • 2
  • j

    jean

    03/18/2023, 3:56 PM
    Any reason for not having something like this in the standard library?
    private fun <T> MutableList<T>.addAll(vararg element: T) = element.forEach { add(it) }
    It’s only possible to pass a collection, an array, an iterable or a sequence as far as I can see. Which is not idealistic when I want to do something like this
    val list = MutableList<Int>()
    when {
      someReason() -> list.addAll(1, 2, 3)
      someOtherReason() -> list.addAll(4, 5, 6)
    }
    a
    e
    • 3
    • 6
  • y

    y

    03/18/2023, 7:30 PM
    is Kotlin’s
    ArrayDeque.removeFirst()
    an
    O(1)
    operation?
  • m

    Mark

    03/19/2023, 3:07 AM
    I kind of understand what is happening here, but how best to explain it?
    fun <T> Foo<T>.getValue(): T
    
    val foo: Foo<Boolean> = ...
    println("no problem: " + foo.getValue())
    val fooAnyValue: Any = foo.getValue()
    println("also no problem: " + fooAnyValue)
    val fooValue = foo.getValue()
    println("class cast exception (fooValue is not a Boolean): " + fooValue)
    a
    i
    • 3
    • 6
  • p

    Pawan

    03/19/2023, 7:48 AM
    Hey everyone, I was going through the documentation for
    callsInPlace
    Kotlin contracts and found an error in it, how can I correct it by contributing? I am new to open source and would love to contribute to Kotlin. Help would be appreciated.
    r
    • 2
    • 2
  • l

    Lukasz Kalnik

    03/20/2023, 9:27 AM
    I'm trying to use JUnit Pioneer
    @CartesianTest.Values
    annotation with an array literal, but I get an error (Kotlin 1.8.10):
    w
    • 2
    • 8
  • v

    vbsteven

    03/20/2023, 6:01 PM
    For a function like this, does it make sense to make it inline?
    public inline fun Boolean.asGBoolean(): Int = if (this) 1 else 0
    h
    l
    +2
    • 5
    • 23
  • j

    Jimmy Zhou

    03/20/2023, 9:15 PM
    Hi Kotlin friends, I am trying to learn how annotation, reflection and continuation works. I appreciate for any comments/directions. Here is my context: I am using spring boot webflux with kotlin coroutine and openapi codegen. I want to be able pass in the request context to my application logic from the webfilter layer all the way to the business logic layer. the challenge i am facing is that: 1. webflux is running on reactor, that means the webfilter layer (interceptor) is running on reactor 2. my controllers are running in coroutine and these points to my business layer 3. my controller interfaces are generated by openapi codegen which does not provide me with flexibility of adding additional parameters (such as the
    webServerExchange
    object). My initial attempt is: 1. pass the context from reactor to coroutine using context capture, and later i can retrieve the context without needing the
    webServerExchange
    object 2. define an customized annotation such as
    WithReactiveContext
    3. add this annotation to my controller class so that all my suspending function will be wrapped inside an different coroutine context (instead of the default one) My questions are: 1. do you guys think this is a legit approach given my context 2. if this approach sounds okay, how do I trigger the annotation method using reflection so that all the suspending functions in annotated class is wrapped within a different coroutine context 3. if this approach does not make sense whats an alternative solution
    s
    • 2
    • 10
  • v

    Vitali Plagov

    03/21/2023, 11:39 AM
    I'm writing Playwright tests with Kotlin and I define the Browser and the Page in my BaseTest class to be created before each test. Like this
    open class BaseTest {
    
        lateinit var browser: Browser
        lateinit var page: Page
    
        @BeforeEach
        fun setUp() {
            browser = Playwright.create().chromium().launch()
            page = browser.newPage()
        }
    }
    But I don't like to use a mutable
    lateinit var
    modifiers. How can I turn these two into immutable variables? Using
    lazy
    ? But then the variable will be initialized only once.
    s
    • 2
    • 2
  • l

    Lukasz Kalnik

    03/21/2023, 3:27 PM
    How can I modify a
    private val
    inside a companion object through reflection?
    j
    e
    • 3
    • 8
  • i

    Ink

    03/22/2023, 3:41 PM
    <?xml version="1.0" standalone="yes"?><svg version="1.1" width="383" height="383">
    How I can get
    width
    and
    height
    value using Regex?
    s
    p
    +2
    • 5
    • 5
  • s

    Sam Stone

    03/22/2023, 4:43 PM
    I am trying to make an observable list, where I have a LiveData/StateFlow that emits the list whenever the list is mutated. I need the list to be iterable by multiple threads/coroutines. This is my signature:
    class ObservableList<T>: MutableList<T> by Collections.synchronizedList(ArrayList()) {
    But when I override a function, it gives an error: Abstract member cannot be accessed directly
    override fun add(element: T): Boolean {
        val add = super.add(element)
        mObserver.postValue(this)
        return add
    }
    s
    e
    s
    • 4
    • 14
  • y

    y

    03/23/2023, 4:14 PM
    I don't understand interfaces with extension functions. say I have
    class Foo(val s: String)
    
    interface MyInterface {
        fun Foo.bar(): String
    }
    
    object MyImpl : MyInterface {
        override fun Foo.bar(): String = this.s
    }
    then given
    val myImpl = MyImpl
    and an instance of
    Foo
    , how/when can I call `MyImpl`'s implementation of
    bar()
    ?
    p
    • 2
    • 4
  • y

    y

    03/23/2023, 5:23 PM
    I've got something like
    interface MyInterface<R> {
        fun doIt(): R
    }
    
    object MyImpl : MyInterface<String> {
        override fun doIt(): String = "hello"
    }
    
    object MyOtherImpl : MyInterface<Int> {
        override fun doIt(): Int = 5
    }
    which works fine. now say I've got
    fun <R> foo(impl: MyInterface<R>): R = impl.doIt()
    is it possible to add a default value to
    impl
    ?
    fun <R> foo(impl: MyInterface<R> = MyImpl) = impl.doIt()
    doesn't compile. the best I could come up with is to also add an overload of `foo`:
    fun foo() = foo(MyImpl)
    .
    p
    l
    • 3
    • 6
  • d

    Daniel

    03/23/2023, 6:39 PM
    Hello, could some one help me with this please? https://stackoverflow.com/questions/75779125/kotlin-compose-how-to-know-when-suspend-function-is-finished
  • k

    Kai Devrim

    03/23/2023, 11:16 PM
    how do i get the keycode of a keypress?
    a
    • 2
    • 1
  • m

    Muhammad Junaid

    03/24/2023, 9:05 AM
    i just need a little bit help, is this could be possible to manual integrate C# sdk in android kotlin project?
    p
    • 2
    • 1
  • d

    David Kubecka

    03/24/2023, 9:55 AM
    Is there any way how to partition a list using an isInstance predicate, so that the matching elements are of the given type?
    val (xs, nonXs) = list.partition { it is X }
    // xs is of type List<X>
    w
    s
    +2
    • 5
    • 30
  • f

    Fray Contreras

    03/24/2023, 2:31 PM
    Hello
  • t

    Tech

    03/24/2023, 6:56 PM
    Hey I was wondering how I could add two lists together like this
    val list1 = listOf("hello", "world")
    val list2 = listOf(*list1, "test")
    I mainly just need to spread list1 into list2 so the type is List<String> on list2
    e
    • 2
    • 2
  • k

    krzysztof

    03/24/2023, 10:26 PM
    Hey, I’m looking for a way to wrap a method into a higher-order function that runs some checks, before running that method. 🧵
    j
    y
    e
    • 4
    • 19
  • j

    Josh Yoo

    03/25/2023, 2:19 AM
    Hello guys, I just need a little help, i want to know the best way to initialize a empty String variable. which way is better, var str =“” or var str = Strings.EMPTY ? I mean using “” vs Strings.EMPTY
    a
    • 2
    • 1
Powered by Linen
Title
j

Josh Yoo

03/25/2023, 2:19 AM
Hello guys, I just need a little help, i want to know the best way to initialize a empty String variable. which way is better, var str =“” or var str = Strings.EMPTY ? I mean using “” vs Strings.EMPTY
a

asdf asdf

03/25/2023, 2:59 AM
Definitely just “” I would say, much clearer as to what’s going on, and it a lot less verbose
View count: 2