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
getting-started
  • e

    elect

    10/01/2021, 11:04 AM
    I'd like to extend this interface and overwrite its method
    interface WebhookEventInterface<T> {
        operator fun invoke(block: WebhookEventInterface<T>.() -> Unit) {..}
    }
    in this way
    interface PushPullRequestFeatures<T> : WebhookEventInterface<T> {
        override operator fun invoke(block: PushPullRequestFeatures<T>.() -> Unit) {..}
    }
    Unfortunately I didn't find a way to successfully infer the new receiver on the lambda. The above code does not override the super method:
    'invoke' overrides nothing
    and there is also a platform clash:
    Platform declaration clash: The following declarations have the same JVM signature (invoke(Lkyge/triggerEvents/PushPullRequestFeatures;Lkotlin/jvm/functions/Function1;)V):
    I've tried to use
    @JvmName
    , but it says:
    '@JvmName' annotation is not applicable to this declaration
    I tried also
    @OverloadResolutionByLambdaReturnType
    by changing the return type, but the clash doesn't go away neither Any idea?
    e
    • 2
    • 2
  • m

    MarkRS

    10/01/2021, 2:48 PM
    In Android Studio I have red all over my code, "import io.ktor.<anything> has "ktor" in red, "serialization" in "import kotlinx.serialization.SerialName" is also red, but the (Android) app builds. Errr, whut? It's only just started happening (although it's not unknown previously here), so I suppose I've changed something, but what could it be?
    p
    j
    +2
    • 5
    • 7
  • b

    Brian Donovan

    10/01/2021, 5:12 PM
    what is the most/ a popular library companies use to store sensitive information like social security number, passwords, etc. into a database?
    v
    c
    k
    • 4
    • 7
  • e

    elect

    10/02/2021, 10:40 AM
    I'd like to create a variable by delegation
    val username by Input { }
    Where
    class Input {
          companion object {
             operator fun invoke(..): Input {
                ..
             }
          }
       }
    And
    internal operator fun Any.getValue(thisRef: Any?, property: KProperty<*>): Input {
        println("$thisRef, thank you for delegating '${property.name}' to me!")
        val pInput = property as KProperty0<Input>
        println(pInput)
        return pInput.get()
    }
    pInput
    is a valid
    KProperty0
    class, but the moment I call
    .get()
    to retrieve
    Input
    , then I get:
    java.lang.UnsupportedOperationException: call/callBy are not supported for this declaration.
    Why? How can I fix it? What is the way to retrieve the
    Input
    instance produced by its own companion object?
    j
    • 2
    • 34
  • s

    Sohel Shaikh

    10/02/2021, 12:06 PM
    I am facing issues setting up atrium project. I wanted to contribute and help solve an issue but I am not able to get the project running. Since this is not an application and a library I don't know how to setup run configurations for the project. I am able to build the project successfully but none of the tests seems to run as there are no run configurations. Project link: https://github.com/robstoll/atrium
    m
    • 2
    • 3
  • a

    Alex

    10/02/2021, 5:46 PM
    Hi All, i'm still learning Kotlin and i'm currently learning how to use scope functions and would like to understand what the following mean for points 1 and 2
    inline fun <T, R> T.let(*block*: (T) -> R): R
    1) <T, R> T what does the extra T outside the <> mean
    2) What does R mean
    k
    j
    • 3
    • 3
  • h

    Hullaballoonatic

    10/02/2021, 9:55 PM
    does kotlin test framework have any way to set up a list of parameters to a test function?
    s
    m
    • 3
    • 7
  • e

    elect

    10/03/2021, 7:40 AM
    I have a configuration lambda
    var configure: Input.() -> Unit
    as a property on
    Input
    itself in order to execute it later on. However, to execute it externally, I have to call
    input.configure(input)
    ... does this sound right? I'm inclined to think so, because if I scope
    input
    , then I can simply call configure as
    input.apply { configure() }
    , but I'd like to have some feedbacks on this
    c
    e
    j
    • 4
    • 9
  • l

    lhwdev

    10/04/2021, 5:00 AM
    Why casting 'some value typed with type argument' does not cause that type to be smartcast? For example, when you have simple function,
    fun <T> test(value: T): T {
        value as Int
        return 123
    }
    Shouldn't this work?
    a
    • 2
    • 3
  • u

    ursus

    10/04/2021, 11:19 AM
    lateinit var .... ::viewModel.isInitialized
    what is this at runtime? should I be vary of calling it too frequently? or is it just null check and assert?
    j
    s
    e
    • 4
    • 14
  • c

    Chris Fillmore

    10/04/2021, 2:19 PM
    Sorry if this is obvious but I just realized I wasn’t sure — is equality in a
    Set
    compared via
    equals()
    ?
    g
    j
    e
    • 4
    • 6
  • a

    Ayfri

    10/04/2021, 8:49 PM
    Hi, when
    infix
    functions are useful ?
    h
    e
    • 3
    • 6
  • j

    Jonathan Hollingsworth

    10/05/2021, 1:16 AM
    Hello. I’ve got a Data Class I’m defining that can represent database columns. I’d like one of the properties on the Data Class to be
    defaultValue
    , but the type of that value is dependent on
    dataType
    property. I was thinking I’d need a union type for
    defaultValue
    , but just found out Kotlin doesn’t support that. I could use
    Any
    , but that breaks the kotlinx.serialization
    @Serialiazable
    annotation. Has anyone got any ideas or can point me in the right direction?
    h
    a
    • 3
    • 4
  • a

    Ahmed

    10/05/2021, 7:13 AM
    Hello, what are the available packages for measuring
    unit-Test-coverage
    written in kotlin with spring boot 2
    h
    • 2
    • 1
  • d

    Daniel Svensson

    10/05/2021, 11:35 AM
    Humm... is there any way to allow passing a
    value class WriteableResource(val ro: Resource)
    to a method only accepting
    Resource
    without explicitly passing its member? Does it have to explicitly implement an interface for
    Resource
    ?
    t
    • 2
    • 9
  • c

    carbaj0

    10/06/2021, 9:29 AM
    Why is it necessary to wrap the
    data class
    with parentheses?
    g
    j
    c
    • 4
    • 4
  • d

    dave08

    10/06/2021, 1:35 PM
    What would be the most ideomatic way to do such a thing in Kotlin?
    val l = listOf(foo1, foo2, foo3)
    
    var found = l.find(::criteria1)
    
    if (found != null) return doAction(found)
    
    var found = l.find(::criteria2)
    
    if (found != null) return doAction2(found)
    
    ...
    t
    w
    • 3
    • 7
  • j

    Jonathan Hollingsworth

    10/07/2021, 3:28 AM
    Hey folks, I want to do something like the following
    val components: List<Component> = BuilderClass(...some stuff...).into(Component)
    I.e. you use the 
    into
     function to take any Class and return a list of that class Something like
    Class BuilderClass(...) {
    
      fun into(klass: KClass<Any>): List<what_goes_here?> {
         ...
    Anyone know if this is possible?
    p
    t
    • 3
    • 7
  • s

    Slackbot

    10/07/2021, 9:49 AM
    This message was deleted.
    g
    g
    • 3
    • 2
  • m

    Michael de Kaste

    10/07/2021, 1:51 PM
    Why does lazy delegation break contracts?
    j
    m
    e
    • 4
    • 22
  • d

    dave08

    10/07/2021, 3:52 PM
    If I have:
    interface Foo {
       fun printlog(msg: String) = "... - $msg"
    }
    
    class Bar : Foo
    How can I get the printlog in the interface to print out
    Bar - some message
    ? If I use
    ${this::class.simpleName}
    it just gives me the interface's name...
    j
    • 2
    • 11
  • t

    Tianyu Zhu

    10/07/2021, 4:03 PM
    Is there an easy to to get the `Class`/`KClass` object of a top-level .kt file?
    k
    j
    +2
    • 5
    • 9
  • l

    Luffy D. Monkey

    10/07/2021, 4:33 PM
    Hi, I recently cloned kotlin github repo, but facing some issue with building it. gradle task
    :kotlin-stdlib:commonSources
    fails with
    No compatible toolchains found for request filter: {languageVersion=6, vendor=any, implementation=vendor-specific} (auto-detect true, auto-download true)
    I am currently on macOS and have installed java6 using brew as mentioned in the README. How to resolve this issue?
    a
    • 2
    • 1
  • j

    Jonathan Hollingsworth

    10/07/2021, 6:29 PM
    I have an unknown data class being passed into a function - which I use reflection on to figure out the arguments and then map to the result of columns in an arbitrary SQL query in a MutableMap. I then want to create an instance of the data class. In Python, it’d be
    MyClass(**mutableMapObj)
    I’ve tried various options using kclass and callBy, but what I really want to do is destructure the mutableMapObj into the class instantiation call. I.e. my
    MyClass.pleaseTakeAMap(mutableMapObj)
    is equivalent to
    MyClass(param1 = mutableMapObj["param1"], param2 = mutableMapObj["param2"]
    Ideally I could do this without have to add to companion object onto each data class.
    v
    j
    • 3
    • 11
  • a

    Alejo

    10/07/2021, 6:31 PM
    Hello everyone! I want to use maxOf with 2 strings but compare by the String.length. Something like
    maxOf("aaaa","zzz")
    and return
    "aaaa"
    . How could I achieve this?
    r
    • 2
    • 2
  • d

    David Lax

    10/08/2021, 12:04 AM
    Hello I am new to Kotlin, I have a function
    public final func<R> change(method: (I) -> R): Mono<R> { .... }
    and I want to mock this function for any input I want to return a Mono.Empty response. How do I do it? I am lost. I am using Mockito
    e
    • 2
    • 1
  • g

    Gilles Barbier

    10/08/2021, 8:29 AM
    Hi, is there a way to retrieve all classes having a custom annotation?
    e
    m
    +2
    • 5
    • 11
  • c

    Coffee Guy

    10/08/2021, 5:41 PM
    Heya \o I'm starting to code Kotlin and I'm really liking it, but the thing is, I have relatively low-end hardware. Running big IDEs like IntelliJ IDEA is a pain for me and can make the system unusable for minutes. I usually code in VSCode or Neovim with extensions. I...personally found that the experience was well, good, but just not that..well. The LSPs for Kotlin overall just suck compared to IJ. Plus installing and setting up Kotlin, JRE and everything wasn't a fun experience at all 😛 This is more of a request, rather than getting help, but can JetBrains please focus on better Kotlin support on IDEs which aren't IntelliJ IDEA?
    c
    a
    r
    • 4
    • 4
  • i

    IbrahimAbousalem

    10/10/2021, 7:05 PM
    Hi guys I was trying to filter upon a sealed class-specific state but the filter function didn't work. Does anyone know how to do filter against sealed classes state? for example:
    sealed class States{
    object Loading:States()
    data Success(val data: String):States()
    }
    
    results.filter{
     it.state is States.Success 
    }.forEach{ successState ->
    println(successState.data) //Error since this still State not Success State
    }
    j
    • 2
    • 2
  • d

    David Lax

    10/11/2021, 2:31 AM
    Anyone can please help with Mockito? I have a method in Kotlin that expects a lambda function and I try to mock it for any arguemnt, how do you do it?
    j
    g
    • 3
    • 2
Powered by Linen
Title
d

David Lax

10/11/2021, 2:31 AM
Anyone can please help with Mockito? I have a method in Kotlin that expects a lambda function and I try to mock it for any arguemnt, how do you do it?
j

Jacob

10/11/2021, 3:47 AM
1. mockito and kotlin don't go well together. mockito matchers return null which plays havoc with koltins non-nullable type. I recommend mockK instead 2. Be liberal with the stubbing of the method. Let the stub work for any lambda. If you want to verify that the right lambda was passed in, you can do a verifcation with argumentCaptor and test the captured argument for correctness
g

Grégory Lureau

10/11/2021, 7:30 AM
1. I suppose it's true if you don't use Mockito-Kotlin. Did you try with that lib @Jacob? Didn't experience issue while working with lambda, but today I'd prefer a SAM (functionnal) interface instead, so that the signature makes more sense (ex:
()->String
can become
UserIdProvider
,
UuidGenerator
...). Maybe another workaround for your issue?
View count: 2