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

    Seri

    08/14/2019, 10:13 PM
    Can a constructor be written as an extension method?
    c
    • 2
    • 9
  • s

    Slackbot

    08/15/2019, 9:57 AM
    This message was deleted.
    k
    • 2
    • 1
  • b

    basher

    08/15/2019, 8:27 PM
    Is there some kind of linter that will warn if a class is not annotated as public or internal? I know there's a KEEP somewhere about adding an explicit access mode to the compiler, but I don't think that's done yet.
    ➕ 2
    j
    • 2
    • 10
  • d

    Dominaezzz

    08/15/2019, 10:12 PM
    Is there a contract to let Kotlin know that my member `val`'s value will stay the same? Basically I need smart casting to work on
    thing
    in
    data class Wrapper(val thing: String?)
    (from another module of course).
    ➕ 3
    m
    d
    • 3
    • 11
  • s

    Slackbot

    08/16/2019, 8:15 AM
    This message was deleted.
    j
    • 2
    • 1
  • d

    Dias

    08/16/2019, 9:02 AM
    Can someone point me at some sort of article/post which give high level overview of lower level implementation of asynchronous apis please? Like how did callbacks help with async in javascript, what sets actual values in futures/promises, what makes kotlin suspended function resume, does something poll state of suspended function etc etc?
    l
    g
    • 3
    • 14
  • c

    coder82

    08/16/2019, 1:22 PM
    I wonder if there was a way to add a parent class to another class i cannot control via reflection, I have some generated code I cannot change
    :kotlin: 1
    d
    l
    c
    • 4
    • 24
  • s

    Seri

    08/16/2019, 4:49 PM
    Is there an adjective for a piece of Kotlin code being more idiomatic? One of my iOS coworkers just pushed a commit message “Made the code more Swifty” and I’m jealous
    s
    d
    +2
    • 5
    • 8
  • j

    josh

    08/16/2019, 4:56 PM
    Time for an emoji poll! 🍅 for "Kotlinesque" 🚀 for "Kotlinify" 😝 for "Kotliny" :kotlin: for "Kotlinize" :kotlin-flag: for "Kotlinish"
    :kotlin: 35
    🚀 4
    🍅 4
    😝 2
    s
    d
    +3
    • 6
    • 9
  • j

    Jon

    08/17/2019, 2:34 AM
    Untitled
    n
    • 2
    • 3
  • j

    Jon

    08/17/2019, 2:35 AM
    I am looking at the implementation of Serializable above and I am unsure how by just applying this annotation, it automatically makes my data class have a new "serializer()" method to it. It doesn't seem like it is doing anything special so this makes me believe there is something hidden happening.
    l
    • 2
    • 2
  • g

    Gunslingor

    08/18/2019, 5:26 PM
    Any idea how to set this up so spring boot serves images back based on routes?
    r
    • 2
    • 1
  • c

    corneil

    08/18/2019, 5:53 PM
    You should use "img/name.png"
    g
    • 2
    • 15
  • a

    asad.awadia

    08/19/2019, 12:52 AM
    Is it just me or the drop down menu that comes in intellij for intellisense/suggestions is painfully slow?
    p
    • 2
    • 4
  • a

    Andrew Gazelka

    08/19/2019, 1:50 AM
    any alternative to
    SendChannel<T>
    which does not have a suspending
    send
    ?
    d
    • 2
    • 3
  • k

    karelpeeters

    08/19/2019, 6:27 AM
    BooleanArray(64) { (long shr it) and 1 != 0 }
    l
    d
    r
    • 4
    • 17
  • s

    Sergio Pro

    08/19/2019, 6:52 AM
    Dumb question. I declare a property in an abstract class as
    protected var counter: Int
    , which is naturally visible in the implementation classes, but not outside. If I try to access protected member from "outside", I get
    Can not access 'counter': it is protected in ...
    compilation error. This is in Kotlin-only code. However from Java I can see all the protected members as well and can access
    getCounter()
    and
    setCounter()
    . Seems like a strange behavior to me and I couldn't fine anything in the docs.
    l
    k
    • 3
    • 8
  • c

    coder82

    08/19/2019, 11:02 AM
    Does the CoroutineExceptionHandler capture also a CancellatioException in the case of launch? What I would like to do is to launch a bunch of coroutines under a SupervisorJob, and I want to, for robustness, relaunch the coroutine if it fails, but not if it's cancelled.
    d
    l
    • 3
    • 9
  • d

    dasz

    08/19/2019, 12:52 PM
    Morning, is there a way to detail the inherited property type and still override it from the base class? Example:
    interface A; class AI: A; interface B (val a: A); class BI (override val a: AI): B
    conversion from A -> to AI where AI derives from A
    p
    d
    • 3
    • 11
  • n

    naitbit

    08/19/2019, 2:56 PM
    Style question: I have some text to process that needs some easy one to one replacements. One of the replacement is changing escaped quote
    \"
    to just quote
    "
    ...I cannot find a readable way to write that down as Pair. I came up with 3 ways to write that down and all of them are borderline unreadable:
    "\\\"" to "\""
    
    """\"""" to """""""
    
    Pair("""
        \"
        """.trimIndent(),
        """
        "
        """.trimIndent())
    e
    k
    • 3
    • 9
  • r

    Robert Menke

    08/19/2019, 5:41 PM
    Is there a go-to way of doing automatic file formatting on save for Kotin in IntelliJ or android studio? I’m sure I could wrangle a custom file watcher but I’m curious if there’s a more standard tool like Prettier in the JS/TS world out there that takes care of it.
    c
    j
    +2
    • 5
    • 4
  • e

    egorand

    08/19/2019, 6:51 PM
    Is there a way to introduce a library-specific experimental marker annotation that serves as an alias to a set of other experimental annotations? Let’s say the library uses API marked with
    @ObsoleteCoroutinesApi
    and
    @ExperimentalCoroutinesApi
    and I don’t want library users to opt into using any of those everywhere in their code, just in the scope of my library. I imagine it has to be something like this:
    @Experimental
    @UseExperimental(ObsoleteCoroutinesApi::class, ExperimentalCoroutinesApi::class)
    annotation class MyExperimental
    but the IDE won’t allow me to use
    @UseExperimental(MyExperimental::class)
    in place of e.g.
    @UseExperimental(ObsoleteCoroutinesApi::class)
    in the library code. Is there a proper way to set it up? Does this approach make sense?
    l
    • 2
    • 4
  • d

    dumptruckman

    08/19/2019, 9:04 PM
    Okay. This is weird
    p
    l
    • 3
    • 6
  • a

    asad.awadia

    08/20/2019, 12:29 AM
    What is the best way to make a kotlin library to share on maven?
    l
    • 2
    • 9
  • l

    LastExceed

    08/20/2019, 5:49 AM
    what does
    XY is marked unstable
    mean?
    g
    • 2
    • 8
  • t

    thana

    08/20/2019, 7:51 AM
    is there something like go present (https://godoc.org/golang.org/x/tools/cmd/present) available for kotlin?
    c
    • 2
    • 2
  • e

    evanchooly

    08/20/2019, 2:53 PM
    https://javap.yawk.at/
    r
    • 2
    • 2
  • g

    Guru

    08/20/2019, 3:18 PM
    fun main(args: Array<String>) {
    
        val subt1: SubServiceType.SUBT1 = SubServiceType.SUBT1(SUBT1Type.SUBT11)
    
        val gson = Gson()
        val str = gson.toJson(subt1, SubServiceType::class.java)
    
        val strJson = "{\"mainServiceType\":\"SUBT21\"}"
    
        val objSubt2Type = gson.fromJson(strJson, ??) //<- PROBLEM IS HERE
    }
    
    enum class MainServiceType(value: Int) {
        MAIN(1),
        MAIN1(2)
    }
    
    interface I1{
        val value:Int
    }
    
    enum class SUBT1Type(override val value: Int) : I1{
        SUBT11(2),
        SUBT12(3)
    }
    
    enum class SUBT2Type(override val value: Int) : I1 {
        SUBT21(2),
        SUBT22(3)
    }
    
    sealed class SubServiceType(val mainServiceType: I1) {
        data class SUBT1(val subServiceType: SUBT1Type) : SubServiceType(subServiceType)
        data class SUBT2(val subServiceType: SUBT2Type) : SubServiceType(subServiceType)
    }
    I am having a problem in serializing this JSON string for sealed class. Any help please?
    m
    • 2
    • 2
  • j

    jaguililla

    08/20/2019, 5:20 PM
    Hi, do someone knows of any Kotlin linter which allow you to fail the build if you have imports of a given package in another's package code?
    👍 1
    j
    s
    • 3
    • 4
  • l

    LeoColman

    08/20/2019, 10:07 PM
    Doing
    nullable?.let { list + it } ?: list
    s
    d
    +2
    • 5
    • 9
Powered by Linen
Title
l

LeoColman

08/20/2019, 10:07 PM
Doing
nullable?.let { list + it } ?: list
s

Shawn

08/20/2019, 10:18 PM
I mean, you could do
nullable?.let(list::add)
👍 1
or, keep it simple w/ an
if (nullable != null)
assuming mutablelist
are you reassigning or building a new read-only list or
d

Daniel

08/20/2019, 10:29 PM
Seems like a good place for a guard case if (nullable == null) return The other stuff seems to only needlessly complicate things.
l

LeoColman

08/20/2019, 11:02 PM
Those are better
I guess sometimes we go for the most complicated version 😅
d

David Glasser

08/21/2019, 4:59 AM
list + (nullable ?: listOf())
r

Ruckus

08/21/2019, 1:35 PM
@David Glasser That won't work unless
nullable
is a list.
View count: 3