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

    luke

    01/29/2020, 2:19 PM
    I'm completely at a loss here as to how to use
    Continuation
    in my Java code when trying to run async coroutines. Anyone have any resources?
    d
    g
    • 3
    • 18
  • s

    Sandy

    01/30/2020, 4:33 AM
    '^((?![Ww][Ee])[ -~])*$'.)]). What does that expression with tilda sign and - mean in regex?
    k
    r
    • 3
    • 7
  • s

    Sandy

    01/30/2020, 4:39 AM
    I want to remove all characters in a given string, which do not match the regex above. How can I accomplish this?
    r
    • 2
    • 1
  • i

    itnoles

    01/30/2020, 5:37 AM
    What is a Kotlin way of
    Collections.sort(contributors, (c1, c2) -> c2.contributions - c1.contributions);
    j
    • 2
    • 1
  • a

    aeruhxi

    01/30/2020, 7:36 AM
    fun x(a: String) {
        print(::a.name) // References to variables aren't supported yet.
    }
    val someVar = 1;
    x(someVar) // ::a.name should be someVar
    Is there a way to know the name of a property or a variable passed to the function by reflection?
    e
    • 2
    • 8
  • i

    ivano

    01/30/2020, 8:18 AM
    Now the challenge is that if I call in my test
    makeCashPeriod()
    I get a nice randomized model, but I need to change some of the parameters depending by the test. Can I achieve that with the language from intelliJ usign something ,do not know, maybe generics, default constructor values, other?
    c
    • 2
    • 5
  • b

    Ben Madore

    01/30/2020, 4:24 PM
    So the reason Spring Data cannot use
    inline
    classes https://jira.spring.io/browse/DATACMNS-1517 - what’s the appropriate place to provide this feedback to the kotlin team on the “experimental” inline classes?
    m
    • 2
    • 1
  • r

    Rob Murdock

    01/30/2020, 4:36 PM
    Is there any way to combine two functions to make a third function such as this?
    val function1: (Int, String, Byte) -> String = { i: Int, s: String, byte: Byte -> "example" }
    
    val function2: (String) -> Int = { -1 }
    
    //to get something like 
    val function3: (Int, String, Byte) -> Int = function1.then(function2)
    obviously the “then” function is fictional otherwise i wouldn’t ask. I’d love to be able to do this without actually having to know function1's arguments explicitly… just that it returns a type that matches the arguments of function2
    r
    r
    • 3
    • 9
  • b

    bbaldino

    01/30/2020, 8:00 PM
    I've got a logging helper function like this:
    inline fun <reified T : Any> T.createChildLogger(
        parentLogger: Logger,
        childContext: Map<String, String> = emptyMap()
    ): Logger =
        parentLogger.createChildLogger(getClassForLogging(T::class.java).name, childContext)
    Which is used to abstract out the logic for obtaining the 'name' of the logger using the caller's class, but I'm finding I can't invoke it in-place when calling a parent constructor, like so:
    class Foo(parentLogger: Logger) : Parent(createChildLogger(parentLogger))
    I assume this is because the receiver function can't be applied here? Is there a workaround for something like this? (either in the definition of
    createChildLogger
    , or how it would be invoked by the child class?
    • 1
    • 5
  • p

    pablisco

    01/30/2020, 10:56 PM
    This is very weird. I have an array converted to a
    List
    using
    Arrays.asList(...)
    coming from Java and when I compare it with a list created with
    listOf()
    in Kotlin: https://pl.kotl.in/cQxTchtL0 Why aren’t following the
    equals
    contract? Anyone experienced this before? 🤔
    d
    • 2
    • 10
  • b

    bbaldino

    01/30/2020, 11:03 PM
    I've found that I can only call a receiver function while invoking a parent class' constructor if a companion object is defined. Is this some subtle type system thing? Or a bug?
    fun <T : Any> T.double(num: Int): Int = num * 2
    
    abstract class Parent(val num: Int)
    
    // Works
    class Child(
        num: Int
    ) : Parent(double(num)) {
        private companion object
    }
    
    // Error: unresolved reference 'double'
    class Child2(num: Int) : Parent(double(num))
    d
    • 2
    • 5
  • a

    Alessandro Tagliapietra

    01/31/2020, 1:51 AM
    for example I have a field like
    {
            "name": "parameters",
            "type": [
              "null",
              {
                "type": "array",
                "items": "Parameter"
              }
            ],
            "default": null
    so it can have a null value but the avro generator generates a java getter like this
    public java.util.List<Parameter> getParameters() {
        return parameters;
    }
    my problem is that when calling getParameters that returns null I get
    java.lang.IllegalStateException: order.getParameters() must not be null
    b
    i
    • 3
    • 9
  • n

    nkiesel

    01/31/2020, 3:17 AM
    I asked the below question a couple of days ago but got no answer. I tried to convince my callers that adding
    .INSTANCE
    is really not a big deal but so far they are not buying it... Anyone has a better idea? I have a mixed Kotlin and Java codebase and a singleton in Kotlin with its methods called from Java. The singleton
    Manager
    delegates all calls to an implementation of an interface
    Service
    (there are multiple possible implementations of
    Service
    ,
    Manager
    picks one at startup). Right now, the code does
    object Manager { val delegate = pickImpl(); @JvmStatic fun foo() = delegate.foo(); @JvmStatic fun bar(a: Int) = delegate.bar(a); ... }
    and the Java code calls
    Manager.foo()
    . This could be simplified to
    object Manager : Service by pickImpl()
    but then the Java code has to be changed to call
    Manager.INSTANCE.foo()
    . Is there a way to use delegation but retain the
    @JVMStatic
    for the Java code?
    m
    • 2
    • 1
  • l

    Luke Rohde

    01/31/2020, 6:02 PM
    i recall someone publishing a kotlin formatter project recently that was more in the style of google-java-format, i.e. the “there’s exactly one correct representation of this code” approach
    • 1
    • 2
  • l

    LS

    01/31/2020, 6:21 PM
    fun <K, V> MutableMap<Set<K>, V>.put2(vararg keys: K, value: V) = put(keys.toSet(), value)
    
    fun main() {
        val map = mutableMapOf<Set<Int>, String>()
        map.put2(1, 2, 3, value = "x") // no errors
        map.put2(1, 2, 3, "x") // compiler error: No value passed for parameter 'value'
    }
    wouldn't it make sense for the compiler to figure the last argument on its own in this scenario?
    c
    s
    • 3
    • 4
  • r

    regu cj

    02/01/2020, 4:33 AM
    @channel Is there any one who is working with lambda functions at a higher level!
    👎 4
    :goberserk: 1
    🤦‍♂️ 7
    😱 1
    😅 1
    t
    c
    +2
    • 5
    • 4
  • h

    Hullaballoonatic

    02/01/2020, 6:53 PM
    so for a multiplaftform desktop/mobile app frontend, do you recommend kotlin-jvm with tornadofx/javafx, or kotlin-js with angular or something?
    r
    r
    • 3
    • 5
  • m

    moltendorf

    02/01/2020, 6:55 PM
    Anyone familiar with Gradle Kotlin DSLs and Multiplatform? I'm attempting to create a shared module between all my platforms but am only stuck when I attempt to do jvm("android") and jvm() as two separate targets (client/server).
    c
    • 2
    • 2
  • l

    Lawik

    02/01/2020, 8:27 PM
    val foo : String? = null
    
    bar(foo)
    
    fun bar(value: Any?){
        when(value){
            is Int? -> println("Int?") // always prints Int? when value == null
            is String? -> println("String?")
        }
    }
    Is there any way to get the actual type of
    value
    ?
    s
    d
    n
    • 4
    • 8
  • m

    mhamade

    02/01/2020, 10:04 PM
    Hi all, do coroutines support the concept of scheduling a task to be run periodically?
    d
    • 2
    • 2
  • e

    Ellen Spertus

    02/02/2020, 12:32 AM
    How do I fix this code?
    private val SUB_REGEXES: Map<String, Pair<Regex, String>> =
      SUBSTITUTIONS.keys.associate {
        it to Pair(Regex("\\b$it\\b", RegexOption.IGNORE_CASE), SUBSTITUTIONS[it])
    }
    It doesn’t compile because
    SUBSTITUTIONS[it]
    is of type
    String?
    instead of the needed `String`; however, I know it is always a
    String
    because its key is in the map
    SUBSTITUTIONS
    . Here’s a rewrite with
    associateWith
    :
    private val SUB_REGEXES: Map<String, Pair<Regex, String>> =
      SUBSTITUTIONS.keys.associateWith { 
        Pair(Regex("\\b$it\\b", RegexOption.IGNORE_CASE), SUBSTITUTIONS[it]) 
    }
    m
    • 2
    • 5
  • t

    Thomas Mao

    02/02/2020, 1:34 PM
    I am learning TornadoFX (Kotlin desktop GUI). Is there anyone know any sample code accessing SQLite from Kotlin desktop app?
    m
    r
    • 3
    • 3
  • b

    Barddo

    02/02/2020, 3:54 PM
    Does anyone know a good alternative to org.json (https://github.com/stleary/JSON-java) more 'Kotlinsh' to read and write json?
    m
    • 2
    • 1
  • c

    Chills

    02/02/2020, 3:58 PM
    @Barddo what are you trying to do?
    b
    • 2
    • 1
  • m

    Matthieu Stombellini

    02/02/2020, 4:30 PM
    Does anyone know if there is a way to import all the members of an enum which is in the same file as where you want to use them? I want to do this:
    // myfile.kt
    enum MyEnum {
      HELLO, GOODBYE, HEY, GREETINGS
    }
    
    fun myFunction() {
      doSomethingWith(HELLO) // instead of MyEnum.HELLO
      doSomethingElse(GOODBYE) // instead of MyEnum.GOODBYE
    }
    I'd normally use
    MyEnum.HELLO
    and
    MyEnum.GOODBYE
    but I have a use case where that causes more harm than anything else. The current workaround I use is to simply declare
    MyEnum
    in a separate file, but that is quite annoying. (please redirect me to the right channel where I can ask this if there's a better place for this question!)
    m
    m
    • 3
    • 3
  • r

    Rodrigo Silva

    02/02/2020, 8:21 PM
    It's possible to do this?
    fun<T: Any> testing( id: UUID, name: String) : T {
    return T
    }
    If no, how do I return a T ?
    🇳🇴 3
    c
    d
    • 3
    • 7
  • c

    camdenorrb

    02/03/2020, 7:25 AM
    Weird appears to only be broken on EAP
    s
    i
    a
    • 4
    • 10
  • j

    Jorgen

    02/03/2020, 8:14 AM
    We’re developing applications using kotlin and spring boot which runs in kubernetes. Are there any issues running kotlin in a java 11 docker image? For example
    adoptopenjdk:11-jre-hotspot
    ? Are there any others more appropriate? And if a kotlin app is developed and run in java 11, are there any reasons for seting jvmTarget = 1.8 i gradle? When i generate a new kotlin java 11 project using spring boot initialiser it sets the
    jvmTarget = "1.8"
    even though i choose java 11 in the project creator.
    c
    • 2
    • 2
  • l

    leodeleon

    02/03/2020, 12:18 PM
    Kotlin Conf Super Early Bird Pricing https://kotlinconf.com/registration/
    c
    n
    +3
    • 6
    • 25
  • m

    myanmarking

    02/03/2020, 3:52 PM
    can any1 tell me what is the usage of Result.kt
    k
    • 2
    • 1
Powered by Linen
Title
m

myanmarking

02/03/2020, 3:52 PM
can any1 tell me what is the usage of Result.kt
k

Kirill Prybylsky

02/03/2020, 3:54 PM
runCatching { //… }.onFailure { // .. }
View count: 2