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

    Rasheed

    12/13/2022, 1:16 PM
    I'm a newbie. I need help with Chuck Norris cipher package chucknorris fun main() { println("Hello World!") } I don't know what to do🙏
    t
    g
    • 3
    • 5
  • d

    dave08

    12/13/2022, 4:09 PM
    Is there any way to make the
    ordinal
    field of an enum start by 2 instead of 0? I'm using a third party ksp parser that uses the ordinal for something that I need to skip the first three numbers for...
    j
    • 2
    • 5
  • d

    dave08

    12/13/2022, 4:20 PM
    Short from doing:
    enum class Foo { NA1, NA2, NA3, Bar, Baz }
    where NAx shouldn't be used... 😛
  • p

    Paul Griffith

    12/13/2022, 10:01 PM
    Is there any easy syntax/shortcut to declare a literal Java
    Class<T?>
    ? E.G. I need a class literal for a
    Double?
    , so I was going to use
    Double::class.javaObjectType
    , but I have to “unsafely” cast that to make the compiler happy. Simplified example of what I’m doing, sort of: https://pl.kotl.in/OQI60v_tV
    r
    b
    • 3
    • 12
  • t

    Todor Grudev

    12/14/2022, 8:57 AM
    data class Coordinate(val x: Int, val y: Int) {
      val bottom: Coordinate = copy(y = y + 1)
    }
    I am trying to do the following thing, but I get
    StackOverflowError
    is it because I am trying to refer something that I am defining?
    r
    r
    • 3
    • 16
  • s

    Sulaimon Abdullahi Oluwaseun

    12/14/2022, 5:43 PM
    👋 Hello, team!
  • n

    Nico Wickersheim

    12/15/2022, 8:32 AM
    Hello, I want to deploy my Ktor App to Heroku. The deployment says “Build successful” but when I start the app, I get application error. Now I saw that I don’t have a .build/install directory in my build folder. This direcotry is referenced in the .Procfile as direction for heroku where to start the app. So how can I create this install directory? Thanks a lot!
    r
    v
    • 3
    • 6
  • m

    martmists

    12/15/2022, 1:55 PM
    Using the following code snippet, and some other code to profile it over 1M iterations with random numbers:
    fun Pair<Int, Int>.sumIsEven() = (first xor second) and 1 == 0
    fun Pair<Int, Int>.sumIsEvenAlt() = (first + second) % 2 == 0
    I would assume the former to be faster as it doesn't require summing and dividing and just does bitwise comparisons, but I'm getting the following results:
    === Case 1 ===
    Average: 42ns
    Max: 546_802ns
    Total: 42_349_933ns
    
    === Case 2 ===
    Average: 36ns
    Max: 52_984ns
    Total: 36_907_022ns
    What's the reason for this difference?
    s
    p
    g
    • 4
    • 5
  • x

    xun su

    12/16/2022, 8:34 AM
    Hi, could someone tell me how to use one companion object field in another one ? why I get some error like
    Variable 'xxx' must be initialized
    ? look the code below:
    class CompanyResource {
        companion object {
            val allNames: Map<String, String> =
                mapOf(
                    someone.first to someone.second // error: Variable 'someone' must be initialized
                )
    
            val someone =
                Pair<String, String>(
                    "peter" , "blunt"
                )
        }
    }
    l
    s
    • 3
    • 3
  • r

    Rob Elliot

    12/16/2022, 10:04 AM
    What's the best way to memoize the result of a delegated property when using
    val x by delegate
    ? I could stick it in a cache in the Delegate class, but wondering if there's a simpler way... I suppose I could wrap it in a lazy, but I'd rather it was eagerly evaluated. I'm really only using it for syntax sugar to reduce boilerplate.
    s
    v
    • 3
    • 18
  • k

    Kirill Grouchnikov

    12/16/2022, 4:58 PM
    Is there any library in Kotlin or Java land that handles a data structure of ranges / intervals? I’ve been playing with https://github.com/lodborg/interval-tree for a bit, but it’s not quite what I’m looking for:
    val tree = IntervalTree<Int>()
    
        tree.add(IntegerInterval(1, 4, Interval.Bounded.CLOSED))
        tree.add(IntegerInterval(6, 8, Interval.Bounded.CLOSED))
        // This ends up with three intervals [0,7], [1,4], [6,8]
        tree.add(IntegerInterval(0, 7, Interval.Bounded.CLOSED))
    What I’m looking for is for the data structure to end up holding the “unified” interval of [0,8] after this third operation. And the same for deletion. If I have a single [0,8] interval and I remove [2,4], it should now have two intervals - [0,2] and [4,8].
    e
    m
    • 3
    • 11
  • t

    trc

    12/16/2022, 9:41 PM
    Hi. Is there a library for parsing command-line options?
    k
    o
    +2
    • 5
    • 9
  • n

    nkiesel

    12/17/2022, 4:56 AM
    Does anyone have a sequence-based implementation for powersets (similar to what Guava provides)?
  • d

    Damien O'Hara

    12/17/2022, 12:29 PM
    hey all, does anyone know where I can find the source code for common kotlin compiler plugins like noarg? have searched to no avail
    • 1
    • 1
  • l

    LastExceed

    12/17/2022, 1:01 PM
    why is this recommended? seems less intuitive to me

    https://i.imgur.com/moQvnG1.png▾

    j
    • 2
    • 2
  • c

    Colton Idle

    12/17/2022, 5:09 PM
    Why does
    arrayListOf
    and `listOf`exist? Both seem to be of Type ArrayList?
    a
    m
    +5
    • 8
    • 11
  • j

    Jan

    12/18/2022, 8:34 PM
    Can you get an annotation of a
    KProperty
    In Kotlin/JS?
    g
    • 2
    • 1
  • k

    Klitos Kyriacou

    12/19/2022, 11:11 AM
    I've just started reading the LinCheck guide. In the example given don't understand how the checker knows what
    inc()
    and
    get()
    are supposed to return, so how can it check if the values are correct?
  • r

    Roach

    12/19/2022, 2:52 PM
    why didn’t add
    @JvmStatic
    when converting java file to kotlin? this result occurs compile error
    k
    j
    • 3
    • 4
  • n

    Nat Strangerweather

    12/19/2022, 6:16 PM
    I don't understand why this function does not work. I expect to get two distinct results and instead I am getting all of the duplicates as well. Any ideas what I am doing wrong?
    items(state.newsFeedItems) {println(listOf(it.feedTitle).distinct())}
    j
    • 2
    • 3
  • g

    Gasan

    12/20/2022, 1:31 PM
    why is this not compiling (complains about lateinit)?
    class SpySleeper: Sleeper {
        lateinit var sleepDuration: Duration
    
        override fun sleep(d: Duration) {
            sleepDuration = d
        }
    }
    
    interface Sleeper  {
        fun sleep(duration: Duration)
    }
    s
    s
    • 3
    • 6
  • g

    Gasan

    12/20/2022, 1:57 PM
    why sources of some kotlin files are missing from the
    kotlin-stdlib
    sources jar?
    i
    • 2
    • 4
  • l

    Lukasz Kalnik

    12/20/2022, 4:26 PM
    Is there a
    BiMap
    (bidirectional hashmap)?
    h
    • 2
    • 2
  • m

    masteramyx

    12/20/2022, 8:17 PM
    Given the lack of an android specific slack workspace, is there a channel here where a "NOT KOTLIN" but Android question can be asked?
    k
    k
    k
    • 4
    • 3
  • m

    martmists

    12/21/2022, 2:21 AM
    How would I achieve the following?
    open class A {
        open fun C.extMethod() { ... }
    }
    
    class B : A() {
        override fun C.extMethod() {
            // Somehow call A's implementation
            // Then do extra behavior
        }
    }
    super.extMethod(this)
    doesn't seem to resolve unfortunately
    j
    s
    • 3
    • 2
  • p

    PHondogo

    12/21/2022, 7:30 AM
    Hello! Consider:
    interface IFace {
      fun test()
      fun test2()
      // etc...
    }
    
    class A : IFace {
      override test() {}
      override test2() {}
      // etc...
    }
    
    class B : IFace {
      private val a = A() // Is it possible to specify that B must delegate all IFace functions to a without passing a in constructor? 
    }
    s
    j
    • 3
    • 8
  • o

    Otis Goodman

    12/22/2022, 3:10 AM
    I am getting a weird error and I am not sure what is causing it or what I need to do to fix it. Consider the following: It appears to be something to do with Kotlinx Sterilization, but I'm not sure what part of my code is causing this.
    java.lang.IllegalStateException: Symbol with IrPropertySymbolImpl is unbound
    	at org.jetbrains.kotlin.ir.symbols.impl.IrBindableSymbolBase.getOwner(IrPrivateSymbolBase.kt:59)
    	at org.jetbrains.kotlinx.serialization.compiler.backend.ir.IrBuilderExtension$DefaultImpls.searchForProperty(GeneratorHelpers.kt:342)
    I can send a link to my code on Github if needed.
    a
    • 2
    • 1
  • d

    dave08

    12/22/2022, 11:44 AM
    If I have a list of
    data class Foo(val bar: String, val baz: Int)
    and I want to only have a list with a unique
    bar
    with the max
    baz
    . Say [0] -> bar = "one", baz = 1 and [1] -> bar = "one", baz = 2, the resulting list should be in the same order and only contain [2]... how do I do this in the most concise and efficient way?
    t
    k
    p
    • 4
    • 16
  • k

    Kai Yuan

    12/23/2022, 1:13 PM
    A quick question regarding
    data class
    and
    set.contains(e)
    If I didn't understand it wrong,
    set.contains(e)
    check
    elementInSet.equals(e)
    . Also, data class creates
    equals()
    method for the properties in the primary constructor. Now, I'm wondering why I get this output:
    m
    c
    • 3
    • 15
  • c

    coroutinedispatcher

    12/23/2022, 2:06 PM
    Hi everyone, for all those getting started with Kotlin, I will be posting some videos under the topic “Kotlin Basics” and then move to more advanced stuff. Playlist can be found here, but I will be updating it every time I post something new.

    https://www.youtube.com/watch?v=xiJdGk7vCT4&amp;list=PL2ByMmD0-yyU2ryekKZqFtSxoWxlfajef▾

Powered by Linen
Title
c

coroutinedispatcher

12/23/2022, 2:06 PM
Hi everyone, for all those getting started with Kotlin, I will be posting some videos under the topic “Kotlin Basics” and then move to more advanced stuff. Playlist can be found here, but I will be updating it every time I post something new.

https://www.youtube.com/watch?v=xiJdGk7vCT4&amp;list=PL2ByMmD0-yyU2ryekKZqFtSxoWxlfajef▾

View count: 8