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

    Vampire

    08/26/2020, 11:20 PM
    Why do breakpoints in suspend functions not work? Is that not supported? Or is it just behaving weird here?
    z
    • 2
    • 3
  • b

    bjonnh

    08/26/2020, 11:45 PM
    Can I get an example of a practical world use of: https://jorgecastillo.dev/kotlin-sam-conversions
    j
    n
    +4
    • 7
    • 10
  • e

    elect

    08/27/2020, 9:22 AM
    hey, does anyone know what else you are supposed to do other than adding
    kotlin.explicitApi()
    to get explicit API mode enabled?
    l
    • 2
    • 14
  • r

    reevn

    08/27/2020, 9:47 AM
    Hey 👋. Did I understand it correctly that with Kotlin
    1.4.0
    the explicit
    kotlin-reflect
    dependency is not needed anymore (in some situations?) as it's included in the standard runtime library?
    u
    • 2
    • 2
  • f

    Fudge

    08/27/2020, 11:29 AM
    I'm having this weird error when using delegated properties in Kotlin 1.4, any idea what is causing it?
    Caused by: java.lang.NoSuchMethodError: kotlin.jvm.internal.FunctionReferenceImpl.<init>(ILjava/lang/Class;Ljava/lang/String;Ljava/lang/String;I)V
    t
    u
    • 3
    • 7
  • t

    thanksforallthefish

    08/27/2020, 11:40 AM
    I am having an upgrade issue as well
    inspection.evaluations.map(::adapt)
    
    fun adapt(evaluation: Evaluation) : EvaluationRepresentationApi
    compiles with 1.3, but does not in 1.4 .
    inspection.evaluations.map { adapt(it) }
    fixes it, but wanted to check if there is a different solution. to be more precise, gradle has no problem, it is idea that complains and fails compilation false, both complain
    a
    • 2
    • 3
  • s

    Sona Hovhannisyan

    08/27/2020, 12:57 PM
    Hey 👋 After migrating to Kotlin 1.4 we are getting the following error when using
    flatMap()
    .
    e: ../SomeClass.kt: Cannot choose among the following candidates without completing type inference: 
    public inline fun <T, R> Iterable<String!>.flatMap(transform: (String!) -> Iterable<???>): List<???> defined in kotlin.collections
    public inline fun <T, R> Iterable<String!>.flatMap(transform: (String!) -> Sequence<???>): List<???> defined in kotlin.collections
    e: ../SomeClass.kt: (158, 49): Unresolved reference: it
    And the code to repro this issue
    fun createStrings(strs: String): List<String> {
        return emptyList<String>()
    }
    ...
    emptyList<String>().flatMap { createStrings(it) }
    Anyone managed to fix this?
    d
    a
    • 3
    • 3
  • m

    Manit Chitkara

    08/27/2020, 2:37 PM
    Hey anyone please suggest any alternatives to xcode for windows or linux?
    m
    • 2
    • 1
  • i

    Iaroslav Postovalov

    08/27/2020, 3:13 PM
    Why can't I pass anonymous functions and function references as
    suspend (...) -> ...
    ?
    • 1
    • 1
  • j

    Joeywp

    08/27/2020, 4:20 PM
    When I add
    compile "org.jetbrains.kotlin:kotlin-reflect:${versions.kotlin_version}"
    (kotlin 1.4.0), it appears it doesn't fully include the reflection as methods like
    primaryConstructor
    and
    declaredMemberProperties
    can't be found. Am I doing something wrong? My jar size increases by 2mb though 🤔
    u
    • 2
    • 4
  • g

    Gunslingor

    08/27/2020, 4:21 PM
    Anyone know what this crazy message means? I'm trying to upgrade to 1.4 but I keep failing on various packages. Thanks!
    • 1
    • 3
  • a

    Adam

    08/27/2020, 5:31 PM
    Does anyone know where I can see the source for the primitive types such as
    Int
    ? I’m interested in seeing how mapping to
    int
    , and boxing to
    java.lang.Integer
    is implemented. So far I found a Generator class: https://github.com/JetBrains/kotlin/blob/master/generators/builtins/primitives.kt And this native generated file, but I can’t see an equivalent for JVM or where the conversion is handled.
    p
    m
    • 3
    • 3
  • s

    snowe

    08/27/2020, 6:41 PM
    Continuing my question from yesterday, I'm still unable to mock (using mockito-kotlin) a call to a java service that takes in varargs. It always returns null.
    private String createObjectsWithRetry(final SObject... objects) {
    ...
        id = crudService.createObjects(objects)[0];
    ...
    }
    
    whenever(crudService.createObjects(anyVararg())).thenReturn(listOf("a","b").toTypedArray())
    whenever(crudService.createObjects(any<SObject>())).thenReturn(listOf("a","b").toTypedArray())
    whenever(crudService.createObjects(any())).thenReturn(listOf("a","b").toTypedArray())
    whenever(sfdcCrudService.createSfdcObjects(argThat{true})).thenReturn(listOf("a","b").toTypedArray())
    ...and more
    The result is always null. I would expect all of these to work, but they do not. I cannot figure out what is wrong. It appears it has to do with how Java treats the varargs being passed as a param straight to a new method.
    m
    • 2
    • 2
  • a

    andylamax

    08/27/2020, 7:27 PM
    Hey, generic wizards. I have another one for you. Among these two, which one is the recommended one? and most importantly, why?
    //case A
    inline reified fun <T:Any?> T.doThing(name: String = T::class.simpleName ?: "") {}
    or
    //case B
    inline reified fun <T:Any> T?.doThing(name: String = T::class.simpleName ?: "") {}
    s
    z
    +2
    • 5
    • 7
  • l

    Luis Munoz

    08/27/2020, 11:20 PM
    is there a more kotlin way to do the following: (interate a list, selecting an item and the item before it and performing an operation on those two elements):
    fun totalDistance(aList: List<Location>) : Double{
                var total: Double = 0.0
                for(x in 1..aList.size-1) {
                    total += distance(aList[x], aList[x-1])
                }
                return total
            }
    a
    t
    • 3
    • 3
  • c

    CodeIdeal

    08/28/2020, 7:10 AM
    pls help me, why there is reporting an error?
    s
    • 2
    • 1
  • j

    janvladimirmostert

    08/28/2020, 8:58 AM
    I have two enums
    enum class Entity {
       PROJECT, WORKSPACE, ...
    enum class Access {
       UPDATE, REMOVE, GRANT, ...
    and i want to write an annotation
    ProjectPermission("$PROJECT.$UPDATE", "$PROJECT.$READ")
    @Repeatable
    @MustBeDocumented
    @Target(AnnotationTarget.FUNCTION)
    @Retention(AnnotationRetention.RUNTIME)
    annotation class ProjectPermission(vararg val permission: String)
    Problem is, the annotation requires a constant, is there a way to convert the String template containing the enums to a constant? The other alternative is to write annotations
    @ProjectPermission(PROJECT, UPDATE)
    , but i can only have one @ProjectPermission on my method with Runtime retention, so the string route allows for more permissions
    m
    m
    • 3
    • 8
  • n

    Niranjan Kurve

    08/28/2020, 10:35 AM
    I have a problem in Boolean class returning Boolean values when compareTo() is overridden and called. As we all know that compareTo() returns Int value whether it is zero, positive or negative. So how can Boolean class implicitly convert it to Boolean form ???????? When I tried to inherit Comparable class on user-defined class it printed same (i.e. Boolean value). Comparable Class : https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-comparable/#functions Boolean Class : https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/compare-to.html
    d
    m
    • 3
    • 15
  • r

    Rechee Jozil

    08/28/2020, 4:46 PM
    uhhh. why does this compile? https://play.kotlinlang.org/#eyJ2ZXJzaW9uIjoiMS4zLjcyIiwicGxhdGZvcm0iOiJqYXZhIiwiYXJncyI6IiIsImpzQ29kZSI6IiIsIm5vbmVNYXJrZXJzIjp0cnVlLCJ0aGVtZSI6ImlkZWEiLCJjb2RlIjoiLyoqXG4gKiBZb3UgY2FuIGVkaXQsIHJ1biwgYW5kIHNoYXJlIHRoaXMgY29kZS4gXG4gKiBwbGF5LmtvdGxpbmxhbmcub3JnIFxuICovXG5cbmZ1biBtYWluKCkge1xuICAgIHZhbCBzdW0xID0gMSArIDJcbiAgICBcbiAgICB2YWwgdGVzdDEgPSAxXG4gICAgdmFsIHRlc3QyID0gMlxuICAgIHZhbCBzdW0yID0gdGVzdDFcbiAgICArIHRlc3QyXG4gICAgcHJpbnRsbihcIiRzdW0xICRzdW0yXCIpXG59In0=
    n
    d
    +2
    • 5
    • 7
  • p

    pniederw

    08/28/2020, 6:19 PM
    Should Kotlin Maven modules have a -javadoc Jar? And should it contain KDoc?
    z
    • 2
    • 1
  • a

    amadeu01

    08/28/2020, 7:30 PM
    People, do you know any tool similar to this https://github.com/muter-mutation-testing/muter for mutating test?
    c
    • 2
    • 1
  • s

    Slackbot

    08/29/2020, 4:17 AM
    This message was deleted.
    👎 1
    🥫 1
    🤦‍♂️ 9
    🚓 6
    🙅 3
    ➖ 28
    z
    c
    +4
    • 7
    • 7
  • h

    Hullaballoonatic

    08/29/2020, 7:43 PM
    Is there anything in kotlin syntax that holds it back from adding python's swapping syntax?
    a, b = b, a
    the only place I can think of where commas are not enclosed in
    ()
    is
    enum
    classes. would that case alone cause python swap syntax to turn kotlin into an irregular language or something? are free-range commas just too dangerous for future expansion? could they not use the same solution as in
    enum
    and require a
    ;
    for only the second time in the language, and thus open up all sorts of destructuring assignment, like that which you see in javascript?
    n
    • 2
    • 41
  • n

    Nir

    08/29/2020, 8:09 PM
    Here's a fun list/map etc challenge i came across in a question in the python slack. Someone was asking how to do this in a dict comprehension, instead of with looping in python:
    [
            ("carrot", ["orange"]),
            ("banana", ["green", "yellow", "black"]),
            ("lemon", ["green", "yellow"]),
            ("apple", ["red", "green"]),
    ]
    
    to
    
    {
        'orange': ['carrot'],
       'green': ['banana', 'lemon', 'apple'],
       'yellow': ['banana', 'lemon'],
       'black': ['banana'],
       'red': ['apple']
    }
    I was able to get it but it's pretty ugly. I tried to think whether there's anything substantially nicer in kotlin, and I couldn't think of anything. Curious to see what folks come up with 🙂
    h
    s
    +3
    • 6
    • 28
  • t

    TwoClocks

    08/29/2020, 11:01 PM
    What's the difference between using a function vs a property for exposing a internal var? Or is there any
    fun time() = internalTime
    vs
    val time = internalTime
    ?
    b
    n
    • 3
    • 60
  • k

    Kroppeb

    08/30/2020, 10:45 AM
    I am porting code between 2 very simillar platforms and from java to kotlin and found it useful to define a bunch of extension functions and normal members and make use of the
    ReplaceWith()
    for
    Deprecated
    to help me. But I've noticed some issues. Am I doing something wrong, or are
    ReplaceWith
    not advanced enough (yet)?
    Untitled
    l
    • 2
    • 2
  • s

    Sivan

    08/31/2020, 8:03 AM
    Thanks for the invite @Alina Dolgikh [JB] 👏
    👋 1
    :kotlin-flag: 1
    l
    • 2
    • 1
  • k

    Karlo Lozovina

    08/31/2020, 11:25 AM
    is it possible to get a "reference" to a HashMap entry? something so that I can write something like this:
    var f = fooMap["key"]
    f = f+1
    🇳🇴 3
    m
    n
    m
    • 4
    • 12
  • r

    rrva

    08/31/2020, 11:26 AM
    will kotlin data classes be implemented using invokedynamic when you target 14+ jvms?
    :no_red: 1
    • 1
    • 1
  • c

    CLOVIS

    08/31/2020, 1:17 PM
    I'd like to be able to write
    val a by delegate1() and delegate2()
    I'm expecting it to have to define
    infix fun Delegate.and(other: Delegate): Delegate {...}
    But since delegation is defined on the presence of methods, and not on the inheritance from an interface, I don't know how to do it :/
    n
    t
    n
    • 4
    • 14
Powered by Linen
Title
c

CLOVIS

08/31/2020, 1:17 PM
I'd like to be able to write
val a by delegate1() and delegate2()
I'm expecting it to have to define
infix fun Delegate.and(other: Delegate): Delegate {...}
But since delegation is defined on the presence of methods, and not on the inheritance from an interface, I don't know how to do it :/
n

Nikky

08/31/2020, 1:19 PM
you might need to write
val a by (delegate1() and delegate2())
and then the returned object/instance from
and
just needs to have the correct functions for delegation
👍 3
the methods are lined out here: https://kotlinlang.org/docs/reference/delegated-properties.html
c

CLOVIS

08/31/2020, 1:20 PM
@Nikky If the function ‘and' takes two
Any
, then I can't call
getValue
on the objects to combine them
And since there's no interface for delegates, I can't put anything else than
Any
?
t

Tobias Berger

08/31/2020, 1:21 PM
just to check if I understood right: you're trying to create an extension function that can somehow combine any 2 delegates and your problem is that delegates don't need to implement a specific interface you could use as a receiver/parameter
c

CLOVIS

08/31/2020, 1:22 PM
Yes, exactly
I guess it's possible to cheat and implement this without combining delegates, I'm mostly doing this out of curiosity to what is possible and what isn't
t

Tobias Berger

08/31/2020, 1:24 PM
I don't think there is any way to do exactly that in kotlin (I guess it would require something like implicit classes or C-style generics). If you only need to use this with delegates you wrote yourself, you could use
ReadOnlyProperty
and
ReadWriteProperty
interfaces, but most default delegate implementations don't extend those.
👍 1
c

CLOVIS

08/31/2020, 1:28 PM
Hm.
I don't understand why the language designers chose not to use inheritance here, it seems weird that that's the only place in the language that doesn't take advantage of it
t

Tobias Berger

08/31/2020, 1:30 PM
well, it's not really the only place. basically all operator functions work without interfaces
n

Nir

08/31/2020, 2:28 PM
C-style generics?
C++ style I guess?
t

Tobias Berger

08/31/2020, 2:28 PM
sure, sorry
View count: 3