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

    xii

    07/15/2020, 4:35 PM
    hey! so i have two enum classes that don't directly depend on each other right now (obviously), but my idea is to make a relationship between the two, because they are actually directly related. let's say one is spell categories, and the other one is spells. so for example, a spell category could be fire, and the spells would only be fire-based spells (following on thread)
    n
    • 2
    • 19
  • n

    Nir

    07/15/2020, 5:45 PM
    Is there a plan for there to be reified generics for inline classes?
    z
    • 2
    • 2
  • b

    Ben Woodworth

    07/15/2020, 6:56 PM
    Is there a way to call super functions/properties with recievers?
    open class A {
        open fun String.x() {
            // implementation
        }
    }
    
    open class B : A() {
        override fun String.x() {
            // implementation
            
            // 'super' is not an expression, it can not be used as a receiver for extension functions
            super.run { this@x.x() }
        }
    }
    Interestingly, when I click on the last
    x
    , IntelliJ highlights the
    x
    function name in
    A
    , and if I remove
    super.
    it'll highlight the
    x
    function name in
    B
    s
    d
    • 3
    • 3
  • n

    Nir

    07/15/2020, 8:54 PM
    is this channel good for a question that has a slightly longer context (~50 lines of code), or is another channel preferable?
    s
    • 2
    • 11
  • n

    Nir

    07/15/2020, 9:08 PM
    Alright, here my question pertains to this code:
    class JsonValue {
        constructor()
    
        sealed class JsonData {
            class IntWrapper(val x: Int) : JsonData()
            class StringWrapper(val x: String) : JsonData()
            class ListWrapper(val x: MutableList<JsonValue>) : JsonData()
            class ObjectWrapper(val x: MutableMap<String, JsonValue>) : JsonData()
            class NullWrapper() : JsonData()
        }
    
        var jsonData: JsonData = JsonData.NullWrapper()
        
        companion object {
            fun make(x: Int): JsonValue {
                val j = JsonValue()
                j.jsonData = JsonData.IntWrapper(x)
                return j
            }
            fun make(x: String): JsonValue {
                val j = JsonValue()
                j.jsonData = JsonData.StringWrapper(x)
                return j
            }
            inline fun <reified T> make(x: List<T>): JsonValue {
                val j = JsonValue()
                j.jsonData = JsonData.ListWrapper(x.map { JsonValue.make(it) })
                return j
            }
        }
    }
    So, json is basically a recursive sum type. Sum types in kotlin are typically done via sealed classes, so I'm doing my best with those. I'm trying to have a generic factory function here that works recursively. The problem is, my generic
    make
    that takes a List complains, because the T is not constrained. However, I can only constrain types in Kotlin by interfaces/classes, and I can't add add any new bases/interfaces to types like Int and String, that I want this to work with conveniently. So, is there any nice way to work around this? Or should I basically declare defeat, change the signature to
    fun make(x: List<JsonValue>)
    and put the onus on the user to convert e.g. a
    List<int>
    into a
    List<JsonValue>
    ?
    a
    d
    • 3
    • 24
  • t

    torres

    07/16/2020, 2:18 PM
    is there some kind of trick to understand this low level kotlin syntax ? I dont understand what is Key, T and * in here
    fun <Key:Comparable<Key>, T: IdTable<Key>> T.insertIgnoreAndGetId(body: T.(UpdateBuilder<*>)->Unit) = InsertStatement<EntityID<Key>>(this, isIgnore = true).run {
        body(this)
        execute(TransactionManager.current())
        getOrNull(id)
    }
    j
    z
    e
    • 4
    • 4
  • b

    bbaldino

    07/16/2020, 3:53 PM
    Is it possible to write a helper method in kotlin so that java code can create a
    KType
    ?
    d
    • 2
    • 12
  • n

    Nir

    07/16/2020, 3:58 PM
    Is there any way at all in Kotlin to be able to have a new constraint on generics, that is met by existing types? AFAICS, generics are only constrainable via inheritance, and you can't make a type you don't control inherit from one of your classes. Is that all there is to it? Is a solution for this being discussed anywhere?
    t
    f
    m
    • 4
    • 213
  • r

    RX

    07/16/2020, 8:00 PM
    Hi i am trying to get data from my database but i am getting error
    Caused by: java.lang.IllegalStateException: Cannot invoke setValue on a background thread
    this is my code written on Java (Im new on Android), someone knows why it’s the problem whit my line?
    v
    i
    +2
    • 5
    • 9
  • a

    ahmad abas

    07/16/2020, 11:14 PM
    what is the
    <http://gobyexample.com|gobyexample.com>
    or
    <http://elixirschool.com|elixirschool.com>
    for kotlin? I usually refer to a short with concise example to get up and running with prog language
    j
    z
    • 3
    • 2
  • a

    allan.conda

    07/17/2020, 8:52 AM
    Trying to threshold compare floats; Is there a standard extension for this?
    l
    • 2
    • 2
  • k

    Klaus

    07/17/2020, 10:25 AM
    Just converting the Java code to Kotlin seems a bit lame to me. 🙂
    j
    n
    • 3
    • 8
  • s

    sksk

    07/17/2020, 12:25 PM
    KotNET "a .NET backend for Kotlin" hmm interesting https://blog.jetbrains.com/blog/2020/07/17/jetbrains-8th-annual-hackathon-home-edition
    🚀 2
    👀 2
    c
    • 2
    • 2
  • n

    natario1

    07/17/2020, 2:19 PM
    Is there a built-in way to do something like
    groupBy { }
    , but only group on elements where the key is contiguous? Say I have a
    List<Sample>
    where sample is
    class Sample(duration: Int)
    . I need something like a
    List<List<Sample>>
    , where samples are grouped by duration, but not reordered. If durations are 100, 100, 100, 200 and 100, that should be three groups, not two.
    p
    d
    k
    • 4
    • 5
  • j

    Jakekudur

    07/17/2020, 2:30 PM
    Hello everyone 👋, does anyone have sample project with RxJava, MVVM, Kotlin, (some DI)?
    a
    • 2
    • 2
  • k

    kenkyee

    07/17/2020, 2:51 PM
    anyone having problems building today if you clean your gradle caches? This appears to have the wrong artifactId: https://bintray.com/kotlin/kotlinx.html/kotlinx.html/0.7.1 looks like "-assembly" has been appended to it compared to previous versions.
    😢 1
    j
    b
    • 3
    • 7
  • x

    xii

    07/17/2020, 5:47 PM
    can takeif be used instead of a normal if else in the following code somehow?
    p
    n
    +3
    • 6
    • 24
  • t

    TwoClocks

    07/17/2020, 7:53 PM
    I do this a lot :
    (1..100).forEach{ }
    but I never reference
    it
    and my linter get's upset w/ me. Is there a better way to do this?
    n
    n
    +2
    • 5
    • 14
  • v

    voben

    07/17/2020, 8:07 PM
    Kotlin nullability/android question. If your backend dev is sending a payload with a String which is never expected to be null, should we be making that string nullable in our response object on the client-side, on the off-chance that the backend sends a null string? Should every response object and its fields be nullable to avoid NPEs?
    c
    j
    +2
    • 5
    • 4
  • h

    hybridDeveloper

    07/18/2020, 6:20 PM
    Hello guys, Does any one have a sample MVI project with Coroutines/Flow or LiveData (Without RxJava) + DI
    z
    • 2
    • 1
  • f

    frank

    07/18/2020, 6:39 PM
    When i work with null-types and I tried to access their attributes, functions etc.. in the members with null-types I need add
    !!
    or
    ?.
    in every call. It's annoying, could be added a feature: Operator that spreads through the members. Sample:
    bob?.department?.head?.name
    bob!!.department!!.head!!.name
    Something like this: [Edit]
    bob.department.head*?.name
    bob.department.head*!!.name
    @Alexey Belkov [JB] , You know if it is on the Road-MAP or if there is any request for this feature? Or would it not be viable? Edit: I'm new with Kotlin but I'm not understand Why this request is so unpopular. Someone to give Feedback
    👎 16
    ➖ 3
    a
    n
    a
    • 4
    • 7
  • k

    Karlo Lozovina

    07/18/2020, 10:27 PM
    huh, tried every possible combination, both with interfaces and inheritance... I guess it's not working, you can't require a class to implement static members... (new to this OOP thing, maybe it's something obvious :D)
    s
    n
    • 3
    • 3
  • i

    itnoles

    07/19/2020, 12:49 AM
    Would JB going to have a plan for XML parsing?
    s
    j
    • 3
    • 6
  • k

    Kroppeb

    07/19/2020, 6:21 PM
    Can I make a java library that has functions that can be interpretted as operator overloading in Kotlin?
    p
    m
    • 3
    • 4
  • n

    Nikky

    07/19/2020, 8:21 PM
    i am encountering a weird error when calling java code that tries to load a private inner class and java throws a
    IllegalAccessError
    the call is
    .addFilter(Query.NumericFilter("price", 0.0, 1000.0))
    which is this java code
    public Query addFilter(Filter f)
    and i think the issue is
    Filter
    which is a private inner class i don't know if there is something wrong with my code or the library.. is this supposed to work in java ? if so.. why does it break here ? or why did they write it like that.. if it does not work just asking if its worth raising a issue over or its a thing related to using kotlin or such
    m
    d
    • 3
    • 5
  • a

    addamsson

    07/20/2020, 11:42 AM
    i'v heard that there is some kind of solution for this but I can't dig up the article where I read about this
    :thread-please: 1
    d
    • 2
    • 3
  • s

    seizma

    07/20/2020, 2:00 PM
    Hi all, I'm trying to use Harmonica (migrations of Exposed). I created migration like this
    import com.improve_future.harmonica.core.AbstractMigration
    import org.jetbrains.exposed.sql.SchemaUtils.create
    import org.jetbrains.exposed.sql.SchemaUtils.drop
    import org.jetbrains.exposed.sql.Table
    
    object Cities : Table("cities") {
      val id = integer("id")
      val name = varchar("name", 20)
    
      override val primaryKey = PrimaryKey(id)
    }
    
    /**
     * Migration
     */
    object : AbstractMigration() {
        override fun up() {
            create(Cities)
        }
    
        override fun down() {
            drop(Cities)
        }
    }
    but when I try to run harmonicaUp it says
    > Task :harmonicaUp FAILED
    Task ':harmonicaUp' is not up-to-date because:
      Task has not declared any outputs despite executing actions.
    :harmonicaUp (Thread[Execution worker for ':',5,main]) completed. Took 0.002 secs.
    
    FAILURE: Build failed with an exception.
    
    * What went wrong:
    Execution failed for task ':harmonicaUp'.
    > org/jetbrains/kotlin/scripting/repl/GenericReplCompiler
    t
    • 2
    • 1
  • e

    Eugene Freeman

    07/20/2020, 4:41 PM
    Hi guys I have a such interface
    interface RequestsExecutor : Closeable {
        suspend fun <T : Any> execute(request: Request<T>): T
    }
    Is possible to implement
    ConstantRequestsExecutor
    to satisfy the interface and use T parameter on the class level? Thanks
    class ConstantRequestsExecutor<T : Any> (
            private val responseValue: T
    ) : RequestsExecutor {
        override fun close() {
        }
    
        override suspend fun execute(request: Request<T>): T {
            return responseValue
        }
    }
    s
    • 2
    • 6
  • u

    user

    07/20/2020, 5:13 PM
    Kotlin/Native Memory Management Roadmap TL;DR: The current automatic memory management implementation in Kotlin/Native has limitations when it comes to concurrency and we are working on a replacement. Existing code will continue to work and will be supported. Read on for the full story. A bit of history Kotlin/Native is designed to be the Kotlin solution for smooth integration with […]
    ❤️ 6
    💪 2
    👍 11
    r
    d
    • 2
    • 2
  • b

    bbaldino

    07/20/2020, 6:37 PM
    Is it possible to use reflection to find all instances of a property Delegate type?
    s
    m
    • 3
    • 10
Powered by Linen
Title
b

bbaldino

07/20/2020, 6:37 PM
Is it possible to use reflection to find all instances of a property Delegate type?
s

stephanmg

07/21/2020, 6:43 AM
I would assume you can use
class.declaredMemberProperties
for that purpose
m

Matteo Mirk

07/21/2020, 3:44 PM
you can’t find all instances of a type with reflection, because it’s meant to introspect types, to access their structure at runtime. If you need to track the instances of a delegate, you need to add a data structure and some logic to save their references
b

bbaldino

07/21/2020, 3:46 PM
Alright, so sounds like maybe I could find all classes within a package, and from there check each
delcaredMemberProperties
to check for the delegate type. Not sure I'll end up doing this, was just curious if there was any good way available.
Thanks 👍
s

stephanmg

07/22/2020, 7:15 AM
maybe look at this @bbaldino
https://stackoverflow.com/questions/39421593/kotlin-how-can-i-get-the-delegation-class-of-a-member-property
if this is of help
b

bbaldino

07/22/2020, 3:25 PM
Thanks! That does help.
s

stephanmg

07/22/2020, 5:15 PM
cool
View count: 1