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

    Hullaballoonatic

    05/16/2019, 2:56 PM
    is there ever a reason to implement
    Comparable
    in kotlin when you can just use
    compareTo
    operator?
    s
    b
    t
    • 4
    • 4
  • h

    Hullaballoonatic

    05/16/2019, 10:23 PM
    why in the world doesn't kotlin have a
    pow
    function for
    Int
    ? Am I an idiot that I can't see it or don't know why?
    p
    • 2
    • 2
  • f

    Florian

    05/19/2019, 12:56 PM
    Should kt file names not contain whitespaces?
    k
    • 2
    • 8
  • s

    Smorg

    05/20/2019, 1:54 AM
    Does anyone have an idea how I can simplify this? The only thing that is changing is the argument name
    when (textInputEditText.id) {
                R.id.editText_fullName -> {
                    setState { copy(signUpData = signUpData.copy(fullName = textInputEditText.text.toString())) }
                }
                R.id.editText_username -> {
                    setState { copy(signUpData = signUpData.copy(username = textInputEditText.text.toString())) }
                }
                R.id.editText_email -> {
                    setState { copy(signUpData = signUpData.copy(email = textInputEditText.text.toString())) }
                }
                R.id.editText_password -> {
                    setState { copy(signUpData = signUpData.copy(password = textInputEditText.text.toString())) }
                }
            }
    s
    • 2
    • 4
  • h

    Hullaballoonatic

    05/20/2019, 6:53 PM
    what are reasons to use enum classes instead of sealed class? so far, i know that: *enums are simpler syntax *enums have a (final😡) name property *enums have ordinals Are sealed classes more space and time costly? Should I avoid using them over enums if all i want is to define the name property myself?
    t
    e
    • 3
    • 8
  • i

    itnoles

    05/20/2019, 6:54 PM
    Possible to use inline sealed class
    h
    • 2
    • 5
  • d

    davidasync

    05/21/2019, 7:10 AM
    Is there any http client library at kotlin that utilize netty ?
    r
    r
    • 3
    • 4
  • m

    Marko Mitic

    05/21/2019, 2:45 PM
    Does anybody knows some ObservableList implementation on Kotlin (or java 😞)?
    r
    c
    s
    • 4
    • 7
  • e

    EnricCamarero

    05/21/2019, 4:33 PM
    Hi there! Anyone into kotlin multiplatform development? I’ve been working on Android so far and moving to more complex gradle builds is being a nightmare 🐿
    s
    r
    • 3
    • 2
  • s

    scottiedog45

    05/21/2019, 6:44 PM
    What is the “+” doing here?
    private val coroutineContext: CoroutineContext
            get() = parentJob + Dispatchers.Default
    s
    • 2
    • 2
  • r

    robnik

    05/22/2019, 8:39 AM
    Three ways to get a task:
    tasks["foo"]
    ,
    tasks.named("foo").get()
    ,
    tasks.getByName("foo")
    . I guess the first is extra in Kotlin, because the language allows the
    []
    syntax for
    get
    , but is there a difference between the second and third?
    m
    s
    n
    • 4
    • 13
  • s

    scottiedog45

    05/22/2019, 5:15 PM
    What is “A” here?
    fun <T : ViewModel, A> singleArgViewModelFactory(constructor: (A) -> T):
            (A) -> ViewModelProvider.NewInstanceFactory {
        return { arg: A ->
            object : ViewModelProvider.NewInstanceFactory() {
                @Suppress("UNCHECKED_CAST")
                override fun <V : ViewModel> create(modelClass: Class<V>): V {
                    return constructor(arg) as V
                }
            }
        }
    }
    r
    p
    • 3
    • 2
  • f

    Florian

    05/25/2019, 9:38 AM
    Which vendor's JDK do people use?
    j
    t
    +3
    • 6
    • 11
  • p

    Pepperbc

    05/26/2019, 12:48 PM
    In kotlin exposed, is there a way to get just the id from a lazily loaded relation? Just accessing it to get the id (which is on the main table and has already been fetched from the db) seems to trigger fetching the whole object.
    k
    • 2
    • 1
  • o

    otakusenpai

    05/26/2019, 4:29 PM
    hello, how do i use klaxon to send JSON data online?
    k
    • 2
    • 1
  • u

    ursus

    05/26/2019, 10:20 PM
    Hi, what is this error about?
    Suspicious equality check: equals() is not implemented in Object
    override fun areContentsTheSame(oldItemPosition: Int, newItemPosition: Int) =
            oldList[oldItemPosition] == newList[newItemPosition] <----------
    Type of the list items is ChatItem, which is a sealed class
    sealed class ChatItem
    
    object ProgressBarItem : ChatItem()
    
    data class ThreadHeaderItem(
        val commenterUsername: String,
        val commenterRealName: String?,
        val commenterImageUrl: String?,
        val commentedUsername: String,
        val commentedRealName: String?,
        val commentedTimestamp: LocalDateTime
    ) : ChatItem(), ThreadPart
    
    data class AddCommentItem(val message: Message) : ChatItem(), ThreadPart
    data class DateItem(val date: LocalDateTime) : ChatItem()
    f
    i
    • 3
    • 5
  • d

    dave08

    05/27/2019, 3:02 PM
    Does return from Kotlin use lambda close the resource? Usually returning from a lambda is without a
    return
    , so am I returning from the outer function bypassing the
    use
    ?
    fun doSomething(): Boolean =
    resource.use {
       if (condition) return false
    }
    d
    • 2
    • 2
  • h

    Hullaballoonatic

    05/27/2019, 6:21 PM
    what is the best way to get
    setA
    to also
    setB
    when called, and
    setB
    to also
    setA
    when called, but not infinite loop them? One calls the other but doesn't allow itself to be called again.
    l
    d
    • 3
    • 25
  • r

    Ruckus

    05/28/2019, 6:37 PM
    nums.indices.reversed()
    👍 1
    h
    • 2
    • 1
  • u

    ursus

    05/29/2019, 2:02 AM
    not sure what you mean
    h
    • 2
    • 2
  • a

    Atendra Singh

    05/29/2019, 2:05 AM
    Admin please create a separate channel for Kotlin-Multiplatform
    m
    s
    • 3
    • 2
  • s

    Slackbot

    05/29/2019, 4:18 AM
    This message was deleted.
    s
    m
    • 3
    • 5
  • j

    jaspersmit

    05/29/2019, 9:36 AM
    is it possible to use elvis operator with multiple statements? like
    val someValueNotNull = somethingReturningNull ?: { sttmt1 stmt2 stmt3 }
    d
    • 2
    • 3
  • p

    poohbar

    05/29/2019, 12:35 PM
    I would like the auto-formatter to help me keep the columns aligned 🤔
    d
    • 2
    • 6
  • d

    dave08

    05/29/2019, 5:39 PM
    What I wanted was to get the backing field created and initial value passed to the constructor all at once, one of the Kotlin conveniences that we got too used to, I guess...
    t
    • 2
    • 4
  • f

    Florian

    05/30/2019, 10:17 AM
    Kotlin bytecode is the same as Java bytecode, right?
    👍 4
    m
    • 2
    • 2
  • o

    oday

    05/30/2019, 4:04 PM
    without resorting to comparing it with null
    s
    j
    k
    • 4
    • 7
  • h

    Hullaballoonatic

    05/31/2019, 2:05 AM
    can someone explain why implemented functions from an interface are not allowed to have default parameters? what use is an abstract method with a default parameter...
    d
    d
    • 3
    • 4
  • f

    Florian

    05/31/2019, 11:02 AM
    naming convention for .kt files is PascalCase, right?
    ✔️ 2
    :yes: 1
    k
    • 2
    • 2
  • n

    nk

    05/31/2019, 7:07 PM
    Hello all, is there a way to do Partial<TypeName> like in TypeScript? I saw this question already asked on [stack overflow](https://stackoverflow.com/questions/50651879/kotlin-feature-like-typescript-partial) but its unanswered. My use case is having a
    data class User(name: String, pass: String, email: String, etc...)
    and then an update method which would take a Partial User so that you'd only have to supply a subset of the fields
    fun update(user: Partial<User>): User {...}
    . Should I just create a new type for this? Such as
    data class PartialUser(name?: String = null, pass?: String = null, email: String = null, etc...)
    .
    s
    i
    • 3
    • 3
Powered by Linen
Title
n

nk

05/31/2019, 7:07 PM
Hello all, is there a way to do Partial<TypeName> like in TypeScript? I saw this question already asked on [stack overflow](https://stackoverflow.com/questions/50651879/kotlin-feature-like-typescript-partial) but its unanswered. My use case is having a
data class User(name: String, pass: String, email: String, etc...)
and then an update method which would take a Partial User so that you'd only have to supply a subset of the fields
fun update(user: Partial<User>): User {...}
. Should I just create a new type for this? Such as
data class PartialUser(name?: String = null, pass?: String = null, email: String = null, etc...)
.
s

serebit

05/31/2019, 7:52 PM
You’ll have to create a second type, yes
👍 1
n

nk

05/31/2019, 9:33 PM
Thanks, good to know what's possible/isn't possible. I ended up creating separate types for create/update in the end. I think its better than partial anyway because their accepted fields vary slightly.
i

Ian White

05/31/2019, 11:34 PM
I have a codegen that handles this. You add a
@PartialDataObjects(["Partial","Create","Update"])
annotation to a data object X and it will create
PartialX
,
CreateX
,
UpdateX
data objects for you. it’s not totally ready for public consumption but i’ve found it super handy for my own projects if you’re interested: https://github.com/stardogventures/stardao/tree/master/stardao-kotlin-partial
View count: 4