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

    Marc Knaup

    05/08/2019, 2:30 PM
    I guess "in inline functions" is just a mistake in the error message?
    s
    s
    • 3
    • 3
  • p

    pajatopmr

    05/08/2019, 4:40 PM
    Is anyone aware of a Slack workspace appropriate for IntelliJ? Perhaps someone from JB might steer me there.
    s
    s
    • 3
    • 5
  • i

    iex

    05/08/2019, 6:09 PM
    something like this:
    val nonOptional = optional ?: Log.e("foo", "optional is not set").also { return }
    s
    l
    • 3
    • 8
  • d

    Dico

    05/08/2019, 8:49 PM
    So I'm obfuscating it but that should go along with removing the metadata.
    k
    • 2
    • 2
  • p

    Paul Woitaschek

    05/09/2019, 7:32 AM
    Anyone else annoyed by the "variable declaration could be inlined" inspection? It wants me to inline this:
    val imageSource = suspendCoroutine<ImageSource> { cont ->
            MaterialDialog(context).show {
              listItems(
                items = ImageSource.values().map { getString(it.nameRes) },
                selection = { _, i, _ ->
                  val imageSource = ImageSource.values()[i]
                  cont.resume(imageSource)
                }
              )
            }
          }
          val uri = when (imageSource) {
            ImageSource.GALLERY -> {
              module<SelectPictureFromGalleryModule>().take()
            }
            ImageSource.TAKE_PICTURE -> null
          }
    into this:
    val uri = when (suspendCoroutine<ImageSource> { cont ->
            MaterialDialog(context).show {
              listItems(
                items = ImageSource.values().map { getString(it.nameRes) },
                selection = { _, i, _ ->
                  val imageSource = ImageSource.values()[i]
                  cont.resume(imageSource)
                }
              )
            }
          }) {
            ImageSource.GALLERY -> {
              module<SelectPictureFromGalleryModule>().take()
            }
            ImageSource.TAKE_PICTURE -> null
          }
    s
    k
    +4
    • 7
    • 10
  • p

    pablisco

    05/09/2019, 9:58 AM
    On https://play.kotlinlang.org how do the platforms differ from each other? I was thinking on using the
    JUNIT
    one but could not find any documentation (wondering what the
    CANVAS
    one is about too 😄 )
    :thread-please: 1
    h
    l
    • 3
    • 10
  • r

    reik.schatz

    05/09/2019, 10:04 AM
    does kotlin have syntactic sugar for nullable types like the for-comprehension / yield thing in Scala? i.e. I have n-nullable variables and I want to yield only if they are all not null (return null otherwise)
    r
    k
    s
    • 4
    • 9
  • n

    nickk

    05/09/2019, 2:50 PM
    Is it possible to write a function with varargs that calls a Java function with varargs of type
    Object
    ? Say, I want a shorter name for Android’s `getString()`:
    @NonNull
        public final String getString(@StringRes int resId, Object... formatArgs) {
            return getResources().getString(resId, formatArgs);
        }
    How do I write a Kotlin function that just forwards its arguments to this
    getString
    ? According to the docs, I should use
    kotlin.Any!
    Android Studio does not even let me add the !. Using just
    vararg Any
    results in
    IllegalFormatExceptions
    s
    l
    • 3
    • 6
  • o

    Ovsyannikov Alexey

    05/10/2019, 12:28 AM
    Hello everybody! I few time ago, I have started to investigate flows in Kotlin Coroutines and have found, that
    BroadcastChannel#asFlow
    extension is using
    consumeEach
    . After this I've found (https://github.com/Kotlin/kotlinx.coroutines/blob/085a4cb7dec4121f51cda832dbe1e223681d3379/kotlinx-coroutines-core/common/src/channels/Channels.common.kt) source file and remember that most part (maybe, all) of consume* methods are obsolete for now. How it will be replaced in flows and when these obsolete extensions will be removed?
    c
    • 2
    • 2
  • e

    elect

    05/10/2019, 10:27 AM
    is there a way to conveniently save an enum type and then later retrieve all the name of that enums?
    m
    n
    d
    • 4
    • 8
  • b

    bodiam

    05/11/2019, 4:25 AM
    Hi all, what am I missing here?
    -.java
    j
    k
    d
    • 4
    • 76
  • o

    Ovsyannikov Alexey

    05/11/2019, 10:28 AM
    Is there some channel for tornadofx?
    🔍 1
    p
    c
    • 3
    • 2
  • a

    aerb

    05/11/2019, 12:32 PM
    Hello 👋, Is there a way to limit access of a block of code to only within a scope? For example, could I somehow have a lambda where assignments outside of scope are not allowed?
    k
    p
    • 3
    • 9
  • k

    krtko

    05/11/2019, 8:15 PM
    Have any of you used the Klock library? https://korlibs.soywiz.com/klock/ It looks pretty awesome. Exactly the usecase for inline classes.
    s
    j
    • 3
    • 5
  • e

    elect

    05/12/2019, 8:34 AM
    is there a way to force boxing on primitives other than using nullability?
    e
    • 2
    • 1
  • y

    Yossi Saiada

    05/12/2019, 9:28 AM
    enum class EnumA {
        A, B;
        val group = EnumB.values().find { this == it.enumA }
    }
    
    enum class EnumB(val enumA: EnumA) {
        A1(EnumA.A),
        B1(EnumA.B),
    }
    
    EnumB.values().map { it.enumA } // => [null, null]
    EnumA.A.group  // == null
    EnumB.values().find { EnumA.A == it.enumA }
    Why does EnumB.enumA, for every EnumB value, equals
    null
    ? (I know it's happening because of the circular dependency (caused by the group property), but I'm not sure it should be like that) Edit: I'm a bit confused. I had thought the reason is the circular dependency, but this code:
    enum class EnumA(val enumB: EnumB) { A(EnumB.B) }
    enum class EnumB(val enumA: EnumA) { B(EnumA.A) }
    EnumB.values().map { it.enumA }
    actually works as expected and return
    [A]
    . 🤨
    i
    • 2
    • 1
  • h

    Heart D

    05/12/2019, 5:59 PM
    hey guys am creating an application that fetches latitudes and longitudes but have failed to know to store them and send them as message to someone
    How_to_save_the_fetched_latitudes_and_longitudes_and_save_them_and_send_thm_as_message.txt
    ❌ 1
    l
    k
    • 3
    • 3
  • v

    Viktor Qvarfordt

    05/12/2019, 8:55 PM
    If I have a channel, how can I “channel.take(5)“, ie. get a list containing the 5 items I would get if I channel.receive() 5 times?
    😒uspend: 1
    k
    • 2
    • 2
  • h

    Heart D

    05/13/2019, 8:11 AM
    Hey guys help on this code whats causing the error
    🤦 8
    d
    r
    g
    • 4
    • 3
  • b

    Bernhard

    05/13/2019, 10:15 AM
    Is there a way to denote nullability using javadoc? I have to ship only one jar due to enterprise madness and annotations seem to have deps as well
    s
    d
    • 3
    • 15
  • a

    amadeu01

    05/13/2019, 12:39 PM
    is it possible to do something like swizzling in kotlin?
    k
    s
    +3
    • 6
    • 12
  • e

    elect

    05/13/2019, 1:54 PM
    is there a way to have a unique method for both Java and Kotlin that plays nice with lambda?
    inline fun method(lambda: () -> Unit) // Java needs at the end `return Unit.INSTANCE;`
    void method(Runnable lambda) // Kotlin needs to wrap it into `Runnable { }` and you dont have inline
    d
    r
    +2
    • 5
    • 6
  • p

    pdegand

    05/13/2019, 4:05 PM
    I have a problem around generics and sealed class. Considering theses classes :
    sealed class Bird
    class Chicken: Bird()
    class Turkey: Bird()
    
    class Egg<T: Bird>
    I want to implement a function
    fun <T: Bird> T.layEgg(): Egg<T>
    . The only way I found to implement it with the compiler being ok with is like that :
    fun <T: Bird> T.layEgg(): Egg<T> {
      return when(this as Bird) {
        is Chicken -> Egg<Chicken>()
        is Turkey -> Egg<Turkey>()
      } as Egg<T>
    }
    
    fun main() {
      val egg: Egg<Chicken> = Chicken().layEgg()
    }
    But IDEA tells me that the first
    as Bird
    in the when is useless, but if I remove it, the compiler complains that the when is not exhaustive. And the final
    as Egg<T>
    is marked as unsafe but I need it because returning an Egg<Chicken> is not and Egg<T>. Is there a way to have this implemented a better wat or is this simply impossible with generics ? Thanks
    s
    b
    • 3
    • 9
  • p

    Paul Woitaschek

    05/13/2019, 4:19 PM
    Is there any active development on inline classes? I find the idea so handy but the implementation is so limited. For example I like to use it for units:
    inline class Calories(val value : Double)
    But now I lose all functionallity of double. If I for example want to sum, substract or divide calories, I need to re-implement these basic math functions ontop of the
    Calories
    class as
    operator fun plus
    etc.
    r
    k
    +2
    • 5
    • 9
  • c

    Chi

    05/13/2019, 4:40 PM
    why it required me to add
    !!
    in my
    while
    loop, while I already check node.right will never be null
    -.kt
    s
    s
    +2
    • 5
    • 12
  • s

    serebit

    05/13/2019, 5:13 PM
    What benefits does the new type inference engine provide? I know it isn’t finished, but I’m wondering why it exists
    p
    a
    r
    • 4
    • 5
  • g

    Guru

    05/14/2019, 5:58 AM
    const com = {
      to:"guru",
      address: {
        add1: "DC",
        add2: "LA"
      },
      phoneno: 767646
    }
    
    const fu = ({address:{add1}, phoneno})=>
    {
      console.log(JSON.stringify(add1));
    }
    
    fu(com)
    l
    • 2
    • 1
  • j

    joelpedraza

    05/14/2019, 3:22 PM
    If `Result`’s
    value
    property is internal how can accessors such as
    fold
    be marked as
    inline
    ?
    s
    • 2
    • 4
  • n

    Nezteb

    05/14/2019, 4:10 PM
    Is there a faster Jackson alternative for parsing JSON in Kotlin?
    d
    c
    +4
    • 7
    • 8
  • a

    Andy Victors

    05/14/2019, 5:16 PM
    What is the reason behind
    objects
    being frozen - technical limitation or a language concept? What us then the alternative of keeping the global modifiable list of, say, users in the app?
    m
    o
    +2
    • 5
    • 16
Powered by Linen
Title
a

Andy Victors

05/14/2019, 5:16 PM
What is the reason behind
objects
being frozen - technical limitation or a language concept? What us then the alternative of keeping the global modifiable list of, say, users in the app?
m

Marko Mitic

05/14/2019, 5:22 PM
Frozen objects are immutable, immutable objects are thread-safe, thread-safe objects remove multi-threading bugs
a

Andy Victors

05/14/2019, 5:24 PM
I see the logic here, but how do I implement [mutable] singleton multithreaded component in Kotlin?
m

Marko Mitic

05/14/2019, 5:31 PM
AtomicReference? https://medium.com/@kpgalligan/kotlin-native-stranger-threads-ep-2-208523d63c8f
Notify me if this helps, I'm also interested in solution but I don't have time to allocate to this right now
o

obobo

05/14/2019, 5:52 PM
What's preventing you from declaring the fields inside an object as
var
, or setting a mutable object (like a
MutableList
) as a field?
a

Andy Victors

05/14/2019, 7:00 PM
Hm.. just checked - I have my mutable list declared inside the object like
private val fetchers: ArrayList<DataSourceFetcher> = ArrayList()
. Will try the same using `var`and report.
c

Casey Brooks

05/14/2019, 8:24 PM
Once an object is frozen, all its children objects are also frozen. The only way to have mutable properties in an
object
for mutable singletons is to use
AtomicReference
or other atomic data structures. I was fighting this a while ago and that really is the only route, unfortunately
o

obobo

05/14/2019, 8:28 PM
Oh, is this a KotlinJS or Android thing? Because JVM objects are just singletons. I just tested out some code with a mutableList field in an object.
i

ilya.gorbunov

05/14/2019, 9:20 PM
@alan.kleiman This is a Kotlin/Native memory model restriction
o

obobo

05/14/2019, 9:21 PM
Ah, I see, thanks.
a

Andy Victors

05/16/2019, 11:23 AM
Any ideas why
AtomicReference
is not available for me? Kotlin '1.3.30'
m

Marko Mitic

05/16/2019, 12:32 PM
Is it available on Native only?
a

Andy Victors

05/16/2019, 12:33 PM
According to documentation - it should be in both Common and Native.
m

Marko Mitic

05/16/2019, 12:34 PM
There's atomicfu that should have multiplaform atomic ops https://github.com/Kotlin/kotlinx.atomicfu
Not sure if that is the right way to go. Can somebody help? @ilya.gorbunov
a

Andy Victors

05/23/2019, 1:45 PM
@Casey Brooks
Once an object is frozen, all its children objects are also frozen.
Is there any option to distinguish between real children (owned) and referenced objects? Currently if I pass some object in constructor to the frozen object, that one is also get frozen which is not what I want.
View count: 4