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

    Chilli

    11/27/2020, 11:54 PM
    Apparently I need to ask something the third time today: Is there any useful application to kinda “redeclaring” a method in an interface extending another interface or is it just a “cosmetic” thing? E.g.
    Untitled
    e
    j
    t
    • 4
    • 6
  • l

    Lazard

    11/28/2020, 1:07 PM
    Hello everyone ! I'm really glad to have joined this server 😊 I have a question about Jetpack Compose (Desktop, but idk if the problem exist in JC Android). Where should I ask 🙂 ?
    s
    • 2
    • 2
  • c

    Cicero

    11/28/2020, 2:25 PM
    Stupid control flow question When(something){ in group1 -> tada1 in group2 -> tada2 } but what if I wanna check when(string) and if the subsequent offered strings contain the value inside of my when?
    val incomingString = "A lot of things that are not interesting but this: ThePath"
    when(incomingString){
            "The Path" -> something
            "No Path" -> something
                else -> somethingElse
    }
    Better example
    a
    n
    +3
    • 6
    • 47
  • c

    Chilli

    11/28/2020, 6:35 PM
    I have some problems with Intellij — the previous instance of the program doesn't stop if I start a new one despite having parallel run disabled. Also, it started for some reason running with Gradle and stopping it with Intellij causes it to “fail”
    v
    a
    e
    • 4
    • 10
  • d

    Dieter Konrad

    11/28/2020, 7:35 PM
    Can someone explain why is 
    Kotlinx.html
     considered type safe?
    f
    n
    • 3
    • 7
  • z

    Zimri Leisher

    11/28/2020, 9:09 PM
    quick question which i feel like i should know the answer to: if i have an immutable map and call .toMutableMap on it and change the resulting map, does it change the first immutable one?
    n
    r
    • 3
    • 12
  • t

    TwoClocks

    11/28/2020, 10:34 PM
    collection class question: If I have a list of varying lengths of positive and negative integers how can I sum the sections w/ the same sign? example
    [-1,-1,-1,1,1,-1,-1]
    should yield
    [-3,2,-2]
    I can't figure out how to do this w/o iterating over the list, and keeping a bunch of mutable state. Is there fancy sequence of collection functions I could use to do this?
    e
    b
    +2
    • 5
    • 32
  • b

    Byron Katz

    11/28/2020, 10:37 PM
    Wouldn't it just be a matter of iterating across, saving which "mode" you are in, negative or positive, and summing that way?
    t
    • 2
    • 2
  • f

    Florian

    11/29/2020, 8:04 AM
    Let's say I have a
    List<User>
    and want to get a
    List<String>
    of their
    name
    property, is there a helper method for this?
    a
    • 2
    • 3
  • a

    Animesh Sahu

    11/29/2020, 9:43 AM
    Seems like there's no lowering / optimization for destructing array declaration of same data type.
    var (e, f, c, d) = arrayOf(1, 10, 12, 55)
    Seems to decompile to:
    Integer[] var6 = new Integer[]{5, 44, 34};
    boolean var8 = false;
    int var2 = ((Number)var6[0]).intValue();
    var8 = false;
    int var3 = ((Number)var6[1]).intValue();
    var8 = false;
    int var4 = ((Number)var6[2]).intValue();
    var8 = false;
    int d = ((Number)var6[3]).intValue();
    Is there a workaround to declare multiple variables concisely but also with an efficient handling performance wise?
    b
    n
    • 3
    • 17
  • s

    SrSouza

    11/29/2020, 4:46 PM
    Hi folks, I'm reading about Dart's null safety and based on their video, it says that Kotlin does not have this "Sound null safety". For what I understand reading the docs (https://dart.dev/null-safety) "Sound null safety" but looks like exactly what kotlin does when you are writing a full kotlin code, like a project that only uses others Kotlin libraries. Can someone clarify why kotlin is not "Sound null safety"? (image taken from

    https://www.youtube.com/watch?v=iYhOU9AuaFs▾

    )
    r
    j
    +3
    • 6
    • 7
  • a

    Animesh Sahu

    11/30/2020, 3:22 AM
    Which is considered as a better style? Enums, sealed classes with singletons, or class with companion objects with val?
    👍 1
    n
    • 2
    • 22
  • b

    Byron Katz

    11/30/2020, 5:45 AM
    Hi all, I'm wondering what is the right channel (that's got some life to it) for talking about "here's this thing I made, looking for comments"?
    l
    k
    v
    • 4
    • 4
  • s

    sns

    11/30/2020, 7:48 AM
    Anyone know why the way I initialize this map compiles fine but throws a JVM error? https://stackoverflow.com/q/65068266/499125
    r
    • 2
    • 2
  • a

    Animesh Sahu

    11/30/2020, 7:52 AM
    This doesn't seem to go away, any body know how to create experimental annotation
    v
    a
    • 3
    • 9
  • r

    Rob Elliot

    11/30/2020, 8:31 AM
    I do wish that the toString of maps, lists and data classes was compilable.
    :blob-thinking-upside-down: 4
    a
    v
    +2
    • 5
    • 25
  • r

    Robert Jaros

    11/30/2020, 1:35 PM
    Is there any ETA for Kotlin 1.4.30?
    👍 1
    🤶 3
    a
    c
    • 3
    • 2
  • a

    Animesh Sahu

    11/30/2020, 3:46 PM
    If a dependency artifact missing for a platform what's correct way to build in such situation? As an example KotlinLogging currently only supports Linux, so is there a way to define actual function which returns empty implementation of some of the expect functions in that lib (till lib extends support to other platform)?
    m
    r
    • 3
    • 3
  • u

    user

    11/30/2020, 5:32 PM
    message has been deleted
    🎉 2
    :kotlin-intensifies: 7
    n
    • 1
    • 1
  • a

    Animesh Sahu

    12/01/2020, 4:28 AM
    Is there a way to suppress "unused" warnings for all the public functions/classes in Intellij? (Java seems to have option but Kotlin doesn't)
    🇳🇴 1
    c
    a
    n
    • 4
    • 5
  • p

    Pavel Sidyakin

    12/01/2020, 1:35 PM
    Hello! Is it possible to create a typealias for an annotation? I want to do something like this (the code doesn't compile):
    import androidx.annotation.FloatRange
    
    typealias ProgressFloatRange = FloatRange(from = 0.0, to = 1.0, fromInclusive = true, toInclusive = true)
    t
    m
    • 3
    • 6
  • b

    Big Chungus

    12/01/2020, 2:20 PM
    For the love of god, I can't find any mention in the docs on how to enable IR mode for JVM target... Maybe anyone here will know?
    😂 2
    s
    r
    +3
    • 6
    • 14
  • j

    jvmusin

    12/01/2020, 4:05 PM
    Hi all! There is a bunch of useful extension methods in Kotlin 1.4 like
    kotlin.collections.sumOf
    . I find it very useful, but I have a use case when I want to overload this function. Suppose I have a simple class
    IntHolder
    and an extension function
    Iterable<T>.sumOf((T) -> IntHolder)
    . How can I use both mine
    sumOf
    and prewritten
    sumOf
    from
    kotlin.collections
    ? I have some workarounds like renaming this method or using
    import as
    for a
    kotlin.collections.sumOf
    , but those are not solutions, but just workarounds. Maybe you know the reason it doesn't work or you know how to make it work? As for me, right now it looks like a bug. I've already asked about this on StackOverflow but got no responses Here. The real use case is actually not that simple, but I believe the code below totally describes the whole situation.
    import kotlin.experimental.ExperimentalTypeInference
    
    data class IntHolder(val x: Int) {
        operator fun plus(other: IntHolder) = IntHolder(x + other.x)
    }
    
    @OptIn(ExperimentalTypeInference::class)
    @OverloadResolutionByLambdaReturnType
    inline fun <T> Iterable<T>.sumOf(f: (T) -> IntHolder) = fold(IntHolder(0)) { acc, i -> acc + f(i) }
    
    fun main() {
        val range = 1..5
        val a = range.sumOf { it * 2 }  //here is an error
        val b = range.sumOf { IntHolder(it * 2) }
    }
    n
    v
    m
    • 4
    • 13
  • n

    Nir

    12/01/2020, 8:55 PM
    When using maps in Kotlin I often find myself writing things out like
    myMap[k] = myMap[k]!! + 1
    or similar, to update the map. Kotlin doesn't seem to allow things like
    myMap[k]!! += 1
    either. Wouldn't it be useful to have a
    modify
    or
    update
    function? Is there one already that I missed? It clarifies intent and avoids the repetition of the key:
    fun MutableMap<K, V>.update(k: K, transform: (V) -> V) { this[k] = transform(getValue(k)) }
    fun MutableMap<K, V>.update(k: K, default: V, transform: (V) -> V) { this[k] = transform(getOrDefault(k, default)) }
    Usage would mean that instead of
    myMap[k] = myMap[k]!! + 1
    you'd be able to write
    myMap.update(k) { it + 1}
    m
    e
    q
    • 4
    • 70
  • a

    Antoine Gagnon

    12/01/2020, 9:35 PM
    Hi everyone! Kind of a weird question but I’m trying to restrict access to a method for any subclass. I’m trying to make a builder like this:
    open class AnimalBuilder {
        val dog: DogBuilder get() = DogBuilder()
    
        open inner class DogBuilder : AnimalBuilder() {
            val pug: PugBuilder get() = PugBuilder()
    
            inner class PugBuilder : DogBuilder()
        }
    }
    
    val pugBuilder = AnimalBuilder().dog.pug 
    val wrongBuilder = AnimalBuilder().dog.dog.dog
    But as you can see, I don’t want the
    DogBuilder
    to be able to access the
    dog
    variable available in
    AnimalBuilder
    . Is there any way to do that?
    m
    j
    m
    • 4
    • 13
  • p

    pniederw

    12/01/2020, 11:10 PM
    How do I suppress the new compiler warning "Name contains characters which can cause problems on Windows"? It doesn't show in IntelliJ, only in the Gradle build.
    a
    • 2
    • 4
  • c

    Cicero

    12/01/2020, 11:30 PM
    I’m getting when using mutableLIstOf<Any>: Type inference failed. The value of the type parameter T should be mentioned in input types (argument types, receiver type or expected type). Try to specify it explicitly. I thought I understood it but trying to provide this type is being quite hard. I don’t understand which syntax I should use. The case is
    private var filteredList = mutableListOf<Any>()
    
    if(filteredList.contains(item.resourceType)
    
    data class Item (
        val resourceType: ResourceType? = null
    )
    Now if I give it the ResourceType straight it works. But I would like to understand why not. PS: The way I’m going around this, for now, I’m surrounding the case with when(type) and giving the type class directly into it ex:
    if(filteredList.contains(ResourceType)
    c
    • 2
    • 3
  • b

    bjonnh

    12/02/2020, 1:47 AM
    If people are interested, I'm making an advent of code kotlin leaderboard: 1080601-f03a9296 .
    n
    e
    • 3
    • 12
  • a

    andylamax

    12/02/2020, 6:51 AM
    There was a YT issue where someone suggested to be able to publish pure common kotlin code (one without expect/actual) that can be imported into any target whatsoever. Can I get a link to that issue?
    a
    • 2
    • 2
  • a

    Animesh Sahu

    12/02/2020, 7:08 AM
    is this intended or a bit misleading?
    a
    • 2
    • 1
Powered by Linen
Title
a

Animesh Sahu

12/02/2020, 7:08 AM
is this intended or a bit misleading?
a

Arkadii Ivanov

12/02/2020, 9:57 AM
Objects are automatically frozen, so can't be mutated. You need to apply @ThreadLocal annotation to the object, not to the variable.
View count: 8