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

    Tomasz Krakowiak

    10/31/2020, 3:51 PM
    I am getting "There are multiple versions of "kotlin-test" used in nodejs build: 1.3.72, 1.4.20-M2. Only latest version will be used." despite there's nowhere "1.3.72" in my sources. Any idea why?
    b
    a
    2 replies · 3 participants
  • i

    Iaroslav Postovalov

    10/31/2020, 5:06 PM
    Is
    contract
    in this function correct?
    Untitled.kt
    a
    l
    +1
    9 replies · 4 participants
  • t

    Twferrell

    11/01/2020, 12:50 AM
    Hi all. I have a strange one here and just hoping someone can point me in some direction. I am trying to publish a Kotlin multi-platform project to a Nexus server. I have the releases repository deployment policy set to "Disable redeploy". For some reason, when using the maven-publish in Gradle, it appears to be doing an update somewhere causing this error: "Received status code 400 from server: Repository does not allow updating assets: maven-releases". I can change the deployment policy to allow "Allow redeploy", which fixes the issue, but that isn't the desired behavior. Any ideas?
    b
    1 reply · 2 participants
  • p

    Pablo

    11/01/2020, 8:53 AM
    Is there any idiomatic way to replace strings which can contains parameters? For instance my string is :
    ANIMAL:TYPE:{variable1};NAME:{variable2};AGE:{variable3};FAMILY:{variable4};
    Note, perhaps
    variable4
    is null/empty and I have anything there, I mean I should be able to replace with "" if it's not present
    f
    r
    +1
    6 replies · 4 participants
  • c

    Caio Costa

    11/01/2020, 2:59 PM
    Hello folks. I'd like to know if there's a way of passing a Named parameter as an argument. For exemple: fun abc(namedArgument: String, value: Int) { abcd(namedArgument = value) } Thanks in advance 👍
    g
    12 replies · 2 participants
  • s

    Slackbot

    11/01/2020, 3:10 PM
    This message was deleted.
    ❓ 1
    n
    a
    +1
    4 replies · 4 participants
  • b

    bjonnh

    11/02/2020, 3:07 AM
    Is it possible for a 3rd party library to disable logging in my main program?
    i
    n
    3 replies · 3 participants
  • b

    Ben Hammond

    11/02/2020, 10:59 AM
    If I want to create a duplicate of an existing (nested) dataclass, but with one single val changeb, I had an idea that Kotlin provides syntax to express this concisely but now I cant for the life of me find a reference to to
    k
    1 reply · 2 participants
  • b

    Ben Hammond

    11/02/2020, 11:00 AM
    it there an idiomatic way to copy a structure, but changing a single field
    y
    4 replies · 2 participants
  • e

    Edoardo Luppi

    11/02/2020, 12:31 PM
    If I need to pass the current JVM class to a static method but I don't really have a class, is this the only way to do it? See image.
    k
    12 replies · 2 participants
  • a

    Alex

    11/02/2020, 1:53 PM
    How would I go about running a simple kotlin script? I want to try out a library and I don't feel like creating a separate project for it, I've found that you could just add
    @file:DependsOn("...")
    annotation on it and it should work, I'm getting an error that "DependsOn" doesn't exist
    :google: 1
    b
    n
    18 replies · 3 participants
  • l

    Lilly

    11/02/2020, 4:59 PM
    stupid question here. I want to ditch the spread operator, but can't find a idomatic solution:
    arrayOf(
                Libraries.APPCOMPAT,
                *Libraries.KotlinExt.getAll(),
                Libraries.TIMBER
        ).forEach { // do sth. }
    getAll()
    returns an array but could als be another type of collection, I'm flexible here. What would be an idomatic solution?
    n
    c
    14 replies · 3 participants
  • a

    Anthony Dahanne

    11/02/2020, 5:27 PM
    hello all; I’ve posted this question in #scripting but I could not get any answers… Does anyone know how to answer ? Thanks in advance ! https://kotlinlang.slack.com/archives/C0BT46EL8/p1603997436049300
    n
    2 replies · 2 participants
  • d

    Dmitry Romanov [JB]

    11/02/2020, 6:18 PM
    ⁉️Call for feedback Hey everyone! Who of you folks visit/use Kotlin language specification? Please DM me or leave a comment under this message, I have some questions for you 🙄
    s
    s
    3 replies · 3 participants
  • c

    christophsturm

    11/02/2020, 7:01 PM
    TIL that this is totally valid kotlin syntax:
    class A class B class C
    (i learned that by a copy paste mistake)
    :mind-blown: 2
    s
    n
    4 replies · 3 participants
  • r

    robstoll

    11/02/2020, 8:11 PM
    Is there an official jetbrains library to get an AST out of a Kotlin file?
    c
    5 replies · 2 participants
  • l

    Leon K

    11/02/2020, 11:54 PM
    Is it true that i should be able to invite others into this server? if yes, how'd i do that? kinda lost in slack's UI, tbh ^^'
    z
    c
    +1
    7 replies · 4 participants
  • k

    kvs

    11/03/2020, 4:55 AM
    can i ask questions related to android here?
    r
    2 replies · 2 participants
  • b

    Bart

    11/03/2020, 7:35 AM
    Is there a way to prevent upcasting generic types of functions when calling them with different argument types? Say I write the following function as a test util:
    /**
     * Asserts that two objects of type [T] are equal.
     */
    infix fun <T> T.shouldBe(that: T) {
        Assertions.assertEquals(that, this)
    }
    So that I can easily write
    data.property shouldBe value
    , this works great. But when I supply two values of different types
    "string" shouldBe 5
    , the compiler doesn't complain. It infers the generic type to be
    Any
    . While valid behaviour, it's not what I want to happen. Is there a way I can tell Kotlin to not upcast the generic type if the argument type is not assignable to the receiver type?
    f
    c
    +1
    4 replies · 4 participants
  • m

    mplain

    11/03/2020, 10:47 AM
    Hi! Spring has a WebClient interface, written in Java That interface has the following method:
    contentType(MediaType contentType)
    In my Kotlin code I call that method, passing a null Intellij IDEA Ultimate 2020.2 highlights it in red, saying: Null cannot be a value of a non-null type MediaType But there are no special annotations on the interface method Why does this happen, and how do I handle it? (I actually pass a nullable value, and the DefaultWebClient implementation calls a method annotated with @Nullable, so it can work with nulls)
    t
    a
    5 replies · 3 participants
  • t

    tim

    11/03/2020, 10:53 AM
    Hello, I have a list with a few thousand entries in it. I need to add an element to the start of the list ... whats the best way to do this? Currently I'm doing this:
    val list = listOf(2,3,4)
    val el = 1
    val next = listOf(el) + list
    Thoughts?
    c
    a
    7 replies · 3 participants
  • d

    df

    11/03/2020, 2:48 PM
    is there a special reason why kotlin has the elvis operator for null values but nothing similar for booleans? A lot of times I'm doing sth. like
    val foo = doSomething(); 
    if (!foo) return;
    and
    val foo = doSomething() ?? return
    would be nice.
    r
    l
    +4
    26 replies · 7 participants
  • b

    Bernhard

    11/03/2020, 3:46 PM
    Just amazed by all the extension functions, no need to
    sequence.flatMap { list.asSequence }
    sequence.flatMap { list }
    is enough
    t
    4 replies · 2 participants
  • s

    Serhii K

    11/03/2020, 6:02 PM
    Hi all! https://stackoverflow.com/questions/4617935/is-there-a-way-to-include-commas-in-csv-columns-without-breaking-the-formatting Who knows a beautiful solution in Kotlin?
    r
    v
    +1
    3 replies · 4 participants
  • j

    Jason5lee

    11/04/2020, 2:33 AM
    Why I can't use
    JvmName
    for the extension method of
    UInt
    . It works for
    Int
    .
    g
    1 reply · 2 participants
  • s

    Shreyas Patil

    11/04/2020, 8:06 AM
    Any official doc or release note regarding JetBrains Compose?
    s
    2 replies · 2 participants
  • a

    AdalPari

    11/04/2020, 9:07 AM
    Hi, I need some help to understand what's going on with a lambda call to an interface. I have the following interface in Java:
    public interface ThreadExecutor {
        void execute(Runnable runnable);
    }
    Which I can call from Kotlin this way:
    threadExecutor.execute { //code }
    But, If I convert the interface to Kotlin, then I get an error in those calls, saying that they expect a Runnable but the return is Unit.
    interface ThreadExecutor {
        fun execute(runnable: Runnable)
    }
    And I have to explicitly create the Runnable object.
    threadExecutor.execute(Runnable { /* Code */ })
    Would be great to understand why it happens, but also any idea on how to better solve it without having to create the Runnable in every call?
    t
    r
    +1
    7 replies · 4 participants
  • r

    ribesg

    11/04/2020, 1:54 PM
    Why doesn’t this work?
    import Scratch_12.MyUITableViewCell.Companion.register
    
    class UITableView
    
    class MyUITableViewCell {
        companion object {
            fun UITableView.register() {}
        }
    }
    
    val tableView = UITableView()
    with(tableView) {
        MyUITableViewCell.register()
    }
    The IDE adds the import but the call to
    register
    is still red and it says it cannot find it and suggests to import it, which does nothing as it’s already imported (example class names are relevant to the use case).
    r
    l
    +1
    13 replies · 4 participants
  • b

    bbaldino

    11/04/2020, 8:05 PM
    Is there a class which more directly represents "block until a condition is met" behavior? Or is the idea to just use
    CountdownLatch
    with a value of 1?
    n
    n
    18 replies · 3 participants
  • b

    Ben Butterworth

    11/04/2020, 9:20 PM
    Does anyone know the motivation behind
    FloatIterator
    ?, we already have
    Iterator<Float>
    https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-float-iterator/
    f
    n
    +2
    9 replies · 5 participants
Powered by Linen
Title
b

Ben Butterworth

11/04/2020, 9:20 PM
Does anyone know the motivation behind
FloatIterator
?, we already have
Iterator<Float>
https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-float-iterator/
f

fred.deschenes

11/04/2020, 9:21 PM
I'm guessing it's like the IntStream/FloatStream/etc and it's just an optimized version that doesn't need to box/unbox the value each time
n

nanodeath

11/04/2020, 9:22 PM
that would also be my guess
b

Ben Butterworth

11/04/2020, 9:27 PM
I’d like to investigate/ learn more, could you suggest an approach?
c

Casey Brooks

11/04/2020, 9:28 PM
There are classes like
FloatArray
,
FloatRange
,
FloatProgression
, etc. for all the primitive types, for similar reasons. Seems like, generally, all data structures of primitives have dedicated classes so the compiler can optimize them to avoid boxing/unboxing
n

nanodeath

11/04/2020, 9:38 PM
https://docs.oracle.com/javase/8/docs/api/java/util/stream/DoubleStream.html the docs are sparse for DoubleStream, but it applies here too
b

Ben Butterworth

11/04/2020, 9:56 PM
public interface DoubleStream extends BaseStream<Double,*DoubleStream*> :mind-blown:
n

nanodeath

11/04/2020, 10:01 PM
public interface BaseStream<T,S extends BaseStream<T,S>>
I know how to use streams, but dive into the implementation and it quickly becomes ... well, more complicated than it seems like it should be. that's one thing I like about Sequences -- mostly they have easy-to-understand implementations
b

Ben Butterworth

11/04/2020, 10:29 PM
In swift, we wouldn’t need the extra
S
because within BaseStream, it is already usable (
Self
is the implementing type). I guess this isn’t possible with Kotlin? The closest is reified types, but this is for functions only
z

Zach Klippenstein (he/him) [MOD]

11/04/2020, 10:38 PM
Yep, kotlin does not have self types.
👍 1
View count: 1