https://kotlinlang.org logo
Docs
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
  • w

    Wesley Acheson

    12/13/2019, 10:00 AM
    is there somewhere that I can ask about the eclipse plugin?
    p
    • 2
    • 1
  • p

    Parthiv Mistri

    12/13/2019, 10:38 AM
    Hello, How to sort a
    ArrayList<Model>
    in which
    Model
    has an
    Int
    value between
    1 to 10
    . I need to sort them in Descending order. Can anyone help me to do this? Thanks
    e
    • 2
    • 4
  • m

    mirror-kt

    12/13/2019, 12:44 PM
    Hello, I'm using kotlinx.serialization, but I used Moshi before to convert JSON to Kotlin classes. However, how can I write to same work with following Moshi's code?
    override fun fromJson(reader: JsonReader): Volumes? {
        val volumes = mutableListOf<Volume>()
    
        while (reader.hasNext()) {
            val path = reader.nextName()
            reader.skipValue()
            volumes.add(Volume(path))
        }
    
        return Volumes(volumes)
    }
    
    override fun toJson(writer: JsonWriter, value: Volumes?) {
        if(value == null) return
        writer.beginObject()
        for(volume in value.volumes) {
            writer.name(volume.path)
            writer.beginObject()
            writer.endObject()
        }
        writer.endObject()
    }
    y
    • 2
    • 2
  • w

    Wesley Acheson

    12/13/2019, 2:29 PM
    is there a good way to "edit" an immutable list. I know Scala uses linked lists and prepends items (basically giving a new head) however I've found myself writing this like this.
    /**
     * Adds a new item to a new list, returning the new list.
     * @param item the item to add to the list
     * @return A new list with `item` added to the end.
     */
    private fun <T> List<T>.add(item: T): List<T> {
        val copy = this.toMutableList()
        copy.add(item)
        return copy
    }
    which as far as I can see creates a new array list by copying the data.
    r
    a
    +2
    • 5
    • 14
  • n

    Nikky

    12/13/2019, 3:01 PM
    idea is acting up...

    https://i.imgur.com/QaHuNPf.png▾

    i am pretty sure all these Exceptions are just fine Throwables...
    a
    • 2
    • 1
  • j

    jojo.lichtenberger

    12/13/2019, 5:17 PM
    What is the equivalent to Javas <? extends R & S> with generics?
    c
    d
    • 3
    • 2
  • s

    snowe

    12/13/2019, 5:33 PM
    Never seen an issue like this before.
    fun a(n: Int)=if (n/3-2 <= 0) 0 else n/3-2 + a(n/3-2)
    results in this error
    Error:(107, 46) Kotlin: Type checking has run into a recursive problem. Easiest workaround: specify types of your declarations explicitly
    c
    k
    • 3
    • 8
  • j

    Jared

    12/14/2019, 3:33 AM
    I've decided I am going to do some technical writing, and since i love Kotlin I want to write about some Kotlin topics. Does anyone have any topics they'd like to see written about?
    p
    a
    • 3
    • 2
  • t

    tipsy

    12/14/2019, 12:06 PM
    are there any convenience methods in the kotlin stb lib for encryption?
    t
    d
    b
    • 4
    • 4
  • v

    v0ldem0rt

    12/14/2019, 3:25 PM
    What are good Kotlin confrences in US SFO area?
    t
    • 2
    • 1
  • k

    Kirill Shepelev

    12/14/2019, 5:00 PM
    Hello. When will Kotlin's inline classes be stable and ready for use in production?
    n
    • 2
    • 1
  • r

    robstoll

    12/14/2019, 6:45 PM
    say I have two functions with the same signature, is it possible to somehow delegate to the other without the need to specify the arguments?
    fun foo(i: Int): String = ...
    fun bar(i: Int): String by foo // does not work, is there another syntax?
    m
    t
    t
    • 4
    • 9
  • t

    Tim McCormack

    12/15/2019, 1:03 AM
    (Scraper?)
    👍🏻 2
    c
    • 2
    • 2
  • v

    Vinicius Carvalho

    12/15/2019, 1:11 AM
    So I guess I'm just wondering what is the right approach here
    j
    m
    • 3
    • 6
  • s

    steenooo

    12/15/2019, 10:04 AM
    Is there an up to date kotlin html dsl library? kotlinx.html seems to be outdated
    c
    • 2
    • 2
  • a

    Ashutosh Panda

    12/15/2019, 12:25 PM
    val list= listOf<Int>(5,3,2,4,2)
    println(list)
    clear(list)
    println(list)
    e
    k
    • 3
    • 7
  • a

    Ashutosh Panda

    12/15/2019, 12:27 PM
    I got one way that is to assign
    list=emptyList()
    is there any other way
    d
    • 2
    • 1
  • t

    thymecypher

    12/16/2019, 2:33 AM
    Has there been any talks to add a sort of middle ground to data classes with arrays, such that you can have the generated implementation plus any necessary additional changes to compensate for arrays?
    t
    h
    j
    • 4
    • 10
  • s

    Shan

    12/16/2019, 4:29 AM
    Posting this here to see if anyone else has some insight 😞
    • 1
    • 1
  • s

    steenooo

    12/16/2019, 8:49 AM
    I came across a java method that takes a java.util.Optional. Does the kotlin lib provide a simple method to convert a nullable to an optional?
    k
    m
    j
    • 4
    • 3
  • j

    Joffrey

    12/16/2019, 10:02 AM
    Hey guys, is there any built-in way to assert equality of doubles/floats in Kotlin tests? I'm especially interested in the JVM platform, but if there are some multiplatform ways from
    kotlin-test
    I'd be happy to learn about them.
    s
    w
    • 3
    • 8
  • a

    Ashutosh Panda

    12/16/2019, 11:46 AM
    Can someone please tell how to create multidimensional array with some exampes
    b
    d
    • 3
    • 24
  • s

    Simon Kågedal Reimer

    12/16/2019, 11:57 AM
    If I do
    someObject.javaClass.kotlin.declaredMemberProperties
    – are there any guarantees about the order of the properties? It seems to be alphabetical in my test, but I don’t see any explicit documentation – can I trust that? Is there any way to get them ordered as in source code?
    s
    • 2
    • 2
  • m

    marstran

    12/16/2019, 4:52 PM
    I stumbled upon some really weird behaviour with sequences while working on todays AdventOfCode. I’ve managed to strip the problem down to these three lines. This throws a StackOverflowError:
    fun main() {
        var curr = listOf(1).asSequence()
    
        curr = curr.map { curr.sum() }
    
        println(curr.sum())
    }
    While this works fine:
    fun main() {
        var curr = listOf(1).asSequence()
    
        val done = curr.map { curr.sum() }
    
        println(done.sum())
    }
    Do anyone know why this happens? It also works if I remove the
    sum
    inside the
    map
    . The weird thing is that it makes a difference whether I assign the result to a new variable or not.
    🤔 1
    m
    w
    • 3
    • 7
  • g

    ghedeon

    12/16/2019, 5:33 PM
    Could it be a bug in type inference? Works fine without
    if
    but fails otherwise. Type mismatch error:
    sealed class Foo
    
    object Valid : Foo()
    object Empty : Foo()
    
    fun doSomething1(): Result<Foo> {
        return Result.failure<Valid>(Exception()).recover { if (true) Empty else Valid }
    }
    Works fine:
    fun doSomething2(): Result<Foo> {
        return Result.failure<Valid>(Exception()).recover { Empty }
    }
    :youtrack: 1
    s
    m
    • 3
    • 6
  • j

    jef

    12/16/2019, 8:06 PM
    i'm trying to understand how to setup customer serialization with polymorphism
    k
    • 2
    • 2
  • k

    Ky Leggiero

    12/16/2019, 9:14 PM
    A question about terminology: Are all methods functions? Does a method have to be a function defined inside the original type definition, or does it include extension functions?
    s
    m
    c
    • 4
    • 10
  • p

    paco

    12/16/2019, 11:51 PM
    Hi, I'm trying to run kotlin-web-demo locally but I get the following error when running `gradlew ::copyKotlinLibs`:
    A problem occurred evaluating project ':kotlin.web.demo.backend'.
    > Could not resolve all files for configuration ':versions:1.3.60:kotlinJS'.
       > Could not resolve org:Kotlin_KotlinRelease_1360_Aggregate:1.3.60-release-155.
         Required by:
             project :versions:1.3.60
          > Could not resolve org:Kotlin_KotlinRelease_1360_Aggregate:1.3.60-release-155.
             > Could not get resource '<https://buildserver.labs.intellij.net/guestAuth/repository/download/Kotlin_KotlinRelease_1360_Aggregate/1.3.60-release-155/teamcity-ivy.xml>'.
                > Could not GET '<https://buildserver.labs.intellij.net/guestAuth/repository/download/Kotlin_KotlinRelease_1360_Aggregate/1.3.60-release-155/teamcity-ivy.xml>'. Received status code 400 from server: Bad Request
    I have realized the url of the teamcity server has changed from
    <http://teamcity.jetbrains.com>
    to
    <https://buildserver.labs.intellij.net>
    and the last one requires a personal certificate. Anyone know how to fix this error?
    a
    • 2
    • 2
  • a

    alexsimo

    12/17/2019, 10:33 AM
    "{\"asdasdasdasd\": \"asd\"}"
    e
    • 2
    • 1
  • s

    ShootingStar

    12/17/2019, 1:01 PM
    The bitwise operations and, or, and xor are familiar to most developers. The only difference between them and their logical counterparts is that they do not short-circuit. - Kotlin Cookbook
    Does anyone can explain what does the short-circuit means ?
    j
    • 2
    • 1
Powered by Linen
Title
s

ShootingStar

12/17/2019, 1:01 PM
The bitwise operations and, or, and xor are familiar to most developers. The only difference between them and their logical counterparts is that they do not short-circuit. - Kotlin Cookbook
Does anyone can explain what does the short-circuit means ?
j

Jaymin.Kim

12/18/2019, 9:44 AM
fun foo() = false
fun boo() = { print("boo!"); true }
print("a = ")
foo() && boo()
print("\nb = ")
foo() and boo()
result:
a =
b = boo!
&&
is short-circuit. this means,
foo()
is
false
, so
boo()
don't need to call. so skipped.
and
is not short-circuit. even
foo()
is
false
,
boo()
will call. This only works for
Boolean
View count: 2