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

    basher

    12/01/2019, 6:11 PM
    Are there any tools that use https://github.com/JetBrains/kotlin/blob/master/libraries/kotlinx-metadata/jvm/ReadMe.md (or something else) to determine a public API diff between 2 versions of a library?
    a
    • 2
    • 1
  • s

    steenooo

    12/01/2019, 7:56 PM
    How do property delegation work? Extension properties can't have a value. but I can delegate them with lazy? Where is the lazy value stored?
    d
    k
    • 3
    • 2
  • g

    Gautam Lad

    12/01/2019, 8:30 PM
    Is this not supported? For the life of me I don’t know how to allow the deserializer to allow me decode null values..
    @Serializer(forClass = Date::class)
    internal object DateSerializer : KSerializer<Date?> {
    d
    • 2
    • 2
  • h

    Hullaballoonatic

    12/01/2019, 10:56 PM
    It'd sure be nice if IDEA had a file icon for sealed classes. i'm always tempted to put all my sealed class members inside the sealed class just to make the icon not the default kotlin file one 🤭
    ➕ 4
    a
    • 2
    • 1
  • k

    karelpeeters

    12/01/2019, 11:05 PM
    It would also be great if the icon didn't change if there were other top-level but private things in a file.
    ➕ 7
    a
    • 2
    • 1
  • k

    Konstantin Petrukhnov

    12/02/2019, 6:06 AM
    Is there changelog for ide kotlin plugin?
    a
    • 2
    • 3
  • f

    frogger

    12/02/2019, 8:46 AM
    How would you implement a rest api
    PATCH
    method where clients can update the properties they want. `null`would be also an allowed value. I'm using the jackson mapper currently and "property not send" and "property is `null`" looks currently the same when using a normal `data`class.
    a
    c
    +2
    • 5
    • 7
  • a

    Ashutosh Panda

    12/02/2019, 12:59 PM
    I want to declare an array of objects for a class and then declare its properties and use the getter statement to assign a value to another property using the declared properties, I understood what is being asked but I am sure about the syntax, help me out
    g
    • 2
    • 15
  • m

    Melvin Biamont

    12/02/2019, 1:40 PM
    Hello, I’ve a question about
    suspend
    function and lambdas: Sometimes, I use lambdas in suspend functions, and inside the lambda, I would like to call another suspend function like this:
    class A(
       private val b: B,
       private val c: C
    ){
       suspend fun doSuspendSomething() {
          b.doSomethingElse {
             c.doAnotherThing() //Doesn't work because lambda is not suspend
          }
       }
    }
    
    interface B{
       suspend fun doSomethingElse(callback: ()-> Unit)
    }
    
    class BImpl: B{
       suspend fun doSomethingElse(callback: ()-> Unit){
          callback()
       }
    }
    
    class C {
       suspend fun doAnotherThing() {
          println("I do something very different.")
       }
    }
    So, my problem is the following: If I simply do:
    interface B{
       suspend fun doSomethingElse(callback: suspend ()-> Unit)
    }
    It won’t work in Unit tests using Mockito (I think it’s because in Java, it add a parameter
    continuation
    ). So, another solution would be to use an inline function like this.
    interface B{
       suspend inline fun doSomethingElse(callback: ()-> Unit)
    }
    But, it doesn’t work, we can’t inline a virtual function. Does someone have a solution here?
    a
    t
    • 3
    • 3
  • s

    Steve

    12/02/2019, 5:02 PM
    In Java, you'd have the Utils class with a bunch of static methods. Is there a more Kotlin-y preferred way of doing this?
    r
    s
    +2
    • 5
    • 6
  • s

    Steve

    12/02/2019, 5:42 PM
    How do I add a submodule to a project in IntelliJ?
    a
    • 2
    • 1
  • k

    Kroppeb

    12/02/2019, 5:42 PM
    Is it me or does debugging a worksheet not work?
    a
    a
    • 3
    • 3
  • a

    Andreas Jost

    12/02/2019, 5:45 PM
    How can I invoke lambdas in Unit Tests with MockK? I'm listening to changes of my view in the presenter's function onViewAttached(view), e.g. onLoginListener:
    view.onLoginListener = {
        launch {
            val user = view.userTextField.getTextProperty()
            val pass = view.passTextField.getTextProperty()
    
            val result = doLogin(user, pass)
            // ...
        } 
    }
    It works perfectly fine on Android and iOS devices, but I can't get tests running. If I invoke view.onLoginListener in the test function, nothing happens. The presenter doesn't run the code block. Here is an excerpt of my test class: (see reply in thread)
    • 1
    • 1
  • f

    Fudge

    12/03/2019, 12:19 AM
    Smartcasting a function type property seems to not work.
    class Foo(val callback: (() -> Unit)? = null) {
        init {
            if (callback != null) {
                callback() // Error: Reference has a nullable type '(() -> Unit)?'
            }
        }
    }
    This works fine:
    class Foo(callback: (() -> Unit)? = null) {
        init {
            if (callback != null) {
                callback() // Error: Reference has a nullable type '(() -> Unit)?'
            }
        }
    }
    And this too:
    class Foo(val callback: (() -> Unit)? = null) {
        init {
            if (callback != null) {
                callback.invoke()
            }
        }
    }
    s
    e
    a
    • 4
    • 4
  • u

    ursus

    12/03/2019, 5:01 AM
    Has anyone clue why my list reference doesnt update when used as method reference
    s
    • 2
    • 14
  • j

    Joey

    12/03/2019, 5:32 AM
    how to properly call suspend functions from activities? I have this issue of wrapping each of suspend functions in
    launch{}
    and it looks a bit messy in my point of view. Any suggestions?
    h
    g
    • 3
    • 4
  • u

    ursus

    12/03/2019, 5:33 AM
    root suspend call needs to be within launch, why is it messy?
    j
    g
    • 3
    • 4
  • u

    ursus

    12/03/2019, 6:53 AM
    fun RecyclerView.Adapter<*>.ifHasFlag(flags: Int, flag: Int, body: () -> Unit): Boolean {
        return if (flags.hasFlag(flag)) {  <--- replace flags with this
            body()
            true
        } else {
            false
        }
    }
    so the callsite within any Adapter looks like
    fun onBindHolder(..., payload) {
         payload.ifHasFlag(FLAG) {
             ...
         }
    }
    i
    • 2
    • 2
  • g

    galex

    12/03/2019, 10:54 AM
    Hello, is it possible to override forEach { } ? When we tried, the IDE at least always redirects to the stdlib, not to the one we implemented on our class. Weird or expected behavior?
    m
    a
    +2
    • 5
    • 8
  • r

    Rick

    12/03/2019, 11:23 AM
    hi, can i defined a function which can be called like "diff{//do some}{// do some}" ?
    k
    b
    +2
    • 5
    • 13
  • b

    Burkhard

    12/03/2019, 11:51 AM
    where would I report bugs in the kotlin playground? I get an AssertionError: Built-in class kotlin.Any is not found. https://pl.kotl.in/flR1fOdg9
    i
    e
    • 3
    • 4
  • a

    Ashutosh Panda

    12/03/2019, 12:12 PM
    Hi can anyone explain me what is singleton class in simple language I can't understant it
    b
    m
    • 3
    • 2
  • k

    Kroppeb

    12/03/2019, 12:17 PM
    Can this be considered a bug? Or should one not expect
    Move lambda argument into parentheses
    to work if the code it's run on has syntax errors. If so why give the option to do so if there are errors?
    Untitled
    e
    • 2
    • 3
  • r

    Ruckus

    12/03/2019, 5:06 PM
    Quick question that just bit me, why does
    TODO()
    throw an
    Error
    instead of an
    Exception
    ? The KDoc for
    NotImplementedError
    says: > An exception is thrown to indicate that a method body remains to be implemented. (It's extra weird considering
    error()
    throws an
    Exception
    )
    s
    c
    • 3
    • 10
  • b

    bbaldino

    12/03/2019, 6:45 PM
    is it possible to "cast" an upper bound on a generic type? i have a method:
    override fun <T : Any> getterFor(valueType: KClass<T>): (String) -> T {
        if (valueType.isSubclassOf(Enum::class)) {
            // Need to call a method which expected KClass<T> where T : Enum<T>
            enumHelper(valueType)
        }
        ...
    }
    i can detect it's an enum, but can't figure out how to cast 'valueType' correctly such that it can be passed to a function which expects a
    KClass<T>
    where
    T : Enum<T>
    s
    c
    • 3
    • 32
  • e

    ec

    12/03/2019, 7:45 PM
    What is the idiomatic Kotlin way to achieve this? Couldnt use channels since I cant find a right way to call send,
    Untitled
    z
    • 2
    • 4
  • s

    Sylvain Patenaude

    12/03/2019, 8:55 PM
    Is there a way in Kotlin to explicitly declare a
    Byte
    or
    UByte
    literal? I know that
    val toto: UByte = 128u
    works when it's an assignment, but I'm looking to make something like this compile:
    while (myUByteArray[index] and 128u == 128u) {
    }
    without having to do an explicit cast like
    128u.toUByte()
    . Thanks! EDIT: According to https://kotlinlang.org/docs/tutorials/kotlin-for-py/primitive-data-types-and-their-limitations.html, I can't without an explicit conversion. I think I will just put the
    128u
    into a local
    val
    .
    d
    • 2
    • 2
  • h

    Hullaballoonatic

    12/03/2019, 9:20 PM
    What are some examples of features that made it into the language because they were proposed by the community?
    a
    • 2
    • 2
  • h

    Hullaballoonatic

    12/03/2019, 9:23 PM
    If
    Byte
    is a
    Number
    , then why isn't a
    Bit
    /`Boolean`? Iirc,
    Boolean
    isn't actually stored with just one bit in memory, but does that actually matter?
    r
    s
    • 3
    • 58
  • r

    Robert Menke

    12/03/2019, 10:00 PM
    PSA you can now opt out of Slack’s WYSIWYG editor 🙌 https://www.reddit.com/r/Slack/comments/e5knxo/you_can_now_optout_from_the_awful_wysiwyg_editor/
    👍 2
    👏 10
    z
    c
    • 3
    • 2
Powered by Linen
Title
r

Robert Menke

12/03/2019, 10:00 PM
PSA you can now opt out of Slack’s WYSIWYG editor 🙌 https://www.reddit.com/r/Slack/comments/e5knxo/you_can_now_optout_from_the_awful_wysiwyg_editor/
👍 2
👏 10
z

Zach Klippenstein (he/him) [MOD]

12/03/2019, 10:06 PM
OMG finally
c

codeslubber

12/03/2019, 10:38 PM
How many times have co’s made that mistake? history repeats whether you know it or not…
View count: 1