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
announcements
  • k

    Kashif

    02/12/2020, 10:59 AM
    “consider default value is $0.00, if the customer types in 1, we will display $0.01 If they type in another 1, we display $0.11. If they type a 0, we display $1.10” how to achieve this in kotlin edittext?
    :google: 15
    s
    • 2
    • 1
  • m

    Michael de Kaste

    02/12/2020, 3:16 PM
    I have a question regarding how to model the following. I have a data class representation of all the supplied data.
    data class Activity(
    	val startTime: LocalDate
    	val endTime: LocalDate
    	val directTime: Int
    	val indirectTime: Int
    	val travelTime: Int
    	val quantity: Int
    )
    It's unsure how this class will be used, but at least, this is the absolute truth of the class. Later on, someone says: I want to use a specific predefined version of this activity, a data class that looks like this:
    data class SpecificActivity(
    	val executionTime: LocalDate
    	val duration: Int
    	val quantity: Int
    )
    but somehow backed by the original, hence; executionTime is just startTime, duration is just endTime - startTime in minutes , and quantity is still the same, the other fields are ignored. But I also want to let everyone know, in the model, that SpecificActivity IS an Activity, just not with the represented fields. such that someone can easily say: I want this SpecificActivity, but I want that other version of it (SomeOtherSpecificActivity, that might not have dates, for example.) I know about backing fields, sealed classes and the like, but none of them really do what I want.
    d
    k
    c
    • 4
    • 5
  • l

    louiscad

    02/12/2020, 4:17 PM
    play.kotl.in/kotl.in/try.kotl.in compiler is down (timing out)
    c
    • 2
    • 3
  • s

    Sam Garfinkel

    02/12/2020, 7:09 PM
    Why does type inference fail for
    extract
    here?
    object Container {
        val contained = mutableMapOf<String, Any>()
    
        inline fun <reified T> extract(name: String): T = contained[name] as T
    }
    
    class Foo {
        val bar: String by lazy {
            Container.extract("Bar")
        }
    }
    Because
    lazy
    is declared to return a
    String
    , shouldn’t the inferred type
    T
    also be
    String
    ?
    f
    z
    • 3
    • 11
  • d

    Dave Jensen

    02/12/2020, 9:23 PM
    I have a variable that I'm initializing with
    val something: Something by lazy {}
    but for unit testing I need to be able to mock retrofit. I'd also prefer that the code for building the Retrofit be encapsulated in the class itself. I have a few ideas but I'd like the Kotlin idiomatic way of doing it.
    a
    c
    s
    • 4
    • 19
  • v

    Viktor Qvarfordt

    02/12/2020, 10:05 PM
    In our code we often have some iterable on which we do several
    map
    and
    filter
    . We have recently gone through the code wiht a profiler and this led us to use
    asSequence
    so that we have
    myIterable.asSequence().map { .. }.map { .. }
    . Why the compiler cannot make this optimization automatically? It’s quite obious that I’m not using the intermediate object.
    s
    f
    • 3
    • 5
  • e

    Ellen Spertus

    02/12/2020, 11:49 PM
    Is there a better way to suppress warnings about unused parameters in callbacks than there was in the answer to this 2015 Stack Overflow question? https://stackoverflow.com/questions/29046636/mark-unused-parameters-in-kotlin/29046925
    t
    • 2
    • 1
  • a

    Ani Mehta

    02/12/2020, 11:52 PM
    Hey, hope this isn't too annoying!
    m
    z
    k
    • 4
    • 9
  • a

    Alessandro Tagliapietra

    02/13/2020, 3:41 AM
    nvm found the issue
    p
    k
    • 3
    • 4
  • n

    Nikky

    02/13/2020, 11:33 AM
    does anyone know of wrappers for material-UI or bootstrap around kotlinx-html ? seems like what i find is all just for react or in kotlin-js context in this project i'd like to reduce the amount of js and just generate html and css using typesafe builders
    👀 1
    s
    r
    +2
    • 5
    • 17
  • t

    thana

    02/13/2020, 1:52 PM
    is there a way to iterate alle subclasses of a sealed class? i mean... in the end arn't sealed class enums on steroids? i can do that with enums 😉
    d
    • 2
    • 3
  • c

    Chills

    02/13/2020, 4:15 PM
    why launch by itself doesnt exist for example when you say launch{} it says
    unresolved reference
    d
    • 2
    • 2
  • u

    user

    02/13/2020, 4:30 PM
    message has been deleted
    😲 3
    f
    a
    +2
    • 4
    • 8
  • f

    Fleshgrinder

    02/13/2020, 5:54 PM
    I wonder why exactly
    private const val
    symbols are kept in the bytecode. I guess for reflection but what if this is not required? There should be some kind of annotation to drop these symbols after they are inlined everywhere, no? (Maybe should post this in #language-proposals but wanted to first hear if someone has another reason than reflection to keep them.)
    m
    • 2
    • 6
  • m

    Mike Hill

    02/13/2020, 6:11 PM
    Had an unwelcome surprise with inline functions the other day. I had a custom inline function with multiple branches that would execute a functional parameter. I didn't realize until looking at the bytecode that functional parameter arguments were actually written out once each time that the functional param is referenced. E.g.:
    inline fun myInlineFun(myCase: Boolean, crossinline doSomething: () -> Unit) {
        if (myCase) {
            doSomething()
        } else {
            println("Start")
            doSomething()
            println("End")
        }
    }
    The argument for the
    doSomething
    param is written out twice in the resulting bytecode. Logically, this makes perfect sense to me -- unless there were a simple way for the compiler to remove the branches (which it does actually do if the condition is trivial, by the way), then the function must be written twice. It can have dangerous implications for uses though, especially if a caller attempts to use a long functional param. I didn't notice a kotlinc or IntelliJ warning/inspection for this. Not sure if there are any other tools which would provide one. Anybody else run into this?
    z
    k
    • 3
    • 3
  • l

    LeoColman

    02/13/2020, 7:42 PM
    Is there anything such as a Kotlin Workspace? When programming in R using RStudio, one can keep a computation in memory, and then continuously write code to use that computation. In Kotlin we usually execute everything, and we don't save the in-betweens. For instance, I want to create a table from data I pulled from the web, but I forgot to add a comma. I have to pull all the data from the web again to use it. Of course I could "cache" it in a file or something, but I'm wondering if there's such a thing already.
    e
    k
    c
    • 4
    • 6
  • s

    Slackbot

    02/13/2020, 9:27 PM
    This message was deleted.
    j
    • 2
    • 1
  • k

    ken

    02/13/2020, 9:33 PM
    How do I dynamically get my subclass name from abstract class? Example I want to replace
    GetSubclassNamehere???
    with whichever subclass called the someMethod().
    abstract class A<T> {
        fun someMethod(item: T?) {
            try {
                if (item == null) {
                    println("GetSubclassNamehere??? received null item")
                    return
                }
            } catch (e: Exception) {
            
            }
        }
    }
    
    class B : A<String>() {
    }
    
    
    fun main() {
        val b: A<String> = B()
        b.someMethod(null)
    }
    d
    • 2
    • 2
  • k

    ken

    02/13/2020, 10:44 PM
    How do I get my Logger to print subclass name instead of abstract class name? https://stackoverflow.com/q/60217253
    d
    a
    • 3
    • 9
  • v

    viralshah

    02/14/2020, 4:29 AM
    does anyone know how I can add a element to the
    notes
    array in the following json object?
    val msg = json { obj( "a" to "b", "notes" to array() ) }
    Also asked this in Klaxon, but don’t know if that channel is too active
    a
    • 2
    • 2
  • t

    Tim Malseed

    02/14/2020, 4:44 AM
    I don’t know what
    json
    or
    obj
    are here, so it’s hard ot say what’s possible. But you may be able to do something like:
    val msg = json { obj( "a" to "b", "notes" to mutableListOf() ) }
    
    (msg.array("notes") as MutableList).add(element)
    v
    • 2
    • 6
  • b

    Bruno_

    02/14/2020, 9:27 AM
    I've found this in the source code
    // exposed as public
    @PublishedApi
    internal fun timer(name: String?, daemon: Boolean) = if (name == null) Timer(daemon) else Timer(name, daemon)
    docs of published contains:
    When applied to a class or a member with internal visibility allows to use it from public inline functions and makes it effectively public.
    the question is: since it's internal why should I care about not making breaking changes to the declaration? It's just there for the purpose of chopping up big public inline functions, no? so published internal inline fun is like a private fun in class, right?
    d
    i
    • 3
    • 5
  • j

    jmfayard

    02/14/2020, 9:44 AM
    Job search question: How would search for opportunities to work remotely as a Kotlin developer? I can do both Android and Backend. I've been on generalists website like Remote OK but they not really focused on Kotlin jobs in europeans timezones
    t
    s
    • 3
    • 6
  • c

    Chills

    02/14/2020, 10:58 AM
    becoming a backend kotlin developer leads to jobless?
    c
    s
    t
    • 4
    • 6
  • f

    Fleshgrinder

    02/14/2020, 11:47 AM
    🤔
    s
    m
    +6
    • 9
    • 51
  • s

    steenooo

    02/14/2020, 1:16 PM
    Is it possible to use
    when
    on a reified generic type?
    inline fun <reified F : Foo, reified B : Bar> convert(input: F) : B {
    when(B) {
    Bar1 -> {}
    Bar2 -> {}
    }
    d
    m
    t
    • 4
    • 17
  • c

    camkadev

    02/14/2020, 1:48 PM
    Is anyone try to compile Kotlin Multiplatform Projects on the Windows (Example https://github.com/jinqian/kotlin-native-chifoumi)? looks like problem is still here, tested on JDK 8 and 13 https://github.com/JetBrains/kotlin-native/issues/1846
    a
    m
    • 3
    • 5
  • a

    aipok

    02/14/2020, 1:53 PM
    how can I improve speed of
    (min..max).toList
    it takes 5000 .. 50000 -> 6.516391 s to generate
    s
    j
    +2
    • 5
    • 7
  • c

    Cyril Scetbon

    02/14/2020, 3:17 PM
    Hey here, anyone can help me with a gradle script ?
    t
    • 2
    • 2
  • f

    frogger

    02/14/2020, 3:39 PM
    any simple thread-based concurrency "framework" for a producer(s) -> queue(s) -> consumer(s) pattern?
    c
    • 2
    • 4
Powered by Linen
Title
f

frogger

02/14/2020, 3:39 PM
any simple thread-based concurrency "framework" for a producer(s) -> queue(s) -> consumer(s) pattern?
c

Casey Brooks

02/14/2020, 3:43 PM
Have you tried Flow? https://kotlinlang.org/docs/reference/coroutines/flow.html
f

frogger

02/14/2020, 4:05 PM
I didn't find anything about queue support. I found that the hard part is to properly terminate the different tasks (beeing threads or whatever) on either success or exception.
maybe the buffering method can do it. worth a test at least, thanks for sharing
c

Casey Brooks

02/14/2020, 4:14 PM
Channels (which Flows use under-the-hood) are all buffered, and tasks can be queued/scheduled from the producer side. Or you could try using Channels directly. Generally, Kotlin discourages the use of raw Threads in favor of coroutines (which can be set up to run on different threads/thread pools)
View count: 1