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

    jeff

    02/03/2021, 3:34 AM
    Let's say I have
    class A {
      fun B.something() { ... }
    }
    something()
    has two receivers, A and B, yeah? I was hoping that would let me do this:
    class B {
      init {
        val a = A()
        a.something()
      }
    }
    but it seems in reality I have to do this:
    class B {
      init {
        val a = A()
        with(a) {
          something()
        }
      }
    }
    Is there a nicer way to get something closer to the first one?
    n
    h
    • 3
    • 7
  • s

    Sanat, Web developer

    02/03/2021, 4:39 AM
    Hello everybody, I am new here. Excited to start with your all.
    👋 6
    🐍 1
    d
    c
    • 3
    • 7
  • s

    Sanat, Web developer

    02/03/2021, 7:35 AM
    Any one official from koltlin community who can answer all my questions
    g
    c
    l
    • 4
    • 17
  • n

    Niklas Gürtler

    02/03/2021, 2:03 PM
    Depends on how you use them - if you
    read
    one socket and it takes a long time for a message to arrive, the thread is blocked and can't
    read
    from another socket, even if data is already available there, so the other socket's can experience poor latency. If you do that on multiple threads, or never need to process I/O simultaneously on multiple sockets anyways, this is moot.
    :thread-please: 3
    k
    • 2
    • 4
  • h

    holgerbrandl

    02/03/2021, 4:51 PM
    Congrats to the 1.4.30 release. I guess its still underway but FYI the corresponding release blog post link on https://kotlinlang.org/releases.html is yet dead.
    j
    l
    • 3
    • 2
  • j

    jlleitschuh

    02/03/2021, 5:32 PM
    https://jfrog.com/blog/into-the-sunset-bintray-jcenter-gocenter-and-chartcenter/
    😱 6
    j
    • 2
    • 1
  • j

    Jurriaan Mous

    02/03/2021, 5:38 PM
    Will there be an advice from JetBrains about this JCenter situation? Since it will seriously impact the Kotlin Ecosystem… Will there maybe be a Jetbrains solution? Since I would trust that more than another random company which is less invested in the Kotlin ecosystem.
    👍 3
    💯 3
    ➕ 4
    v
    t
    +5
    • 8
    • 23
  • k

    Kirill Grouchnikov

    02/03/2021, 7:44 PM
    I think the first step is to start filing bugs on librariers to migrate off of Bintray / JCenter. I filed https://github.com/valich/intellij-markdown/issues/64 - which is a dependency of Dokka.
    n
    l
    s
    • 4
    • 4
  • s

    serebit

    02/03/2021, 11:03 PM
    I guess I'm not submitting new versions of my personal libs for a while, given that Maven Central requires signing files, and signing within GitLab CI is just begging for someone to steal the keys. Hopefully someone builds an alternative soon.
    n
    v
    e
    • 4
    • 20
  • p

    Patrick Ramsey

    02/04/2021, 6:43 AM
    does KMP have a built-in handy dandy cross-platform mechanism that approximates the functionality of ServiceLoader, or do I just need to bite the bullet and have this process be slighlty more manual?
    t
    • 2
    • 2
  • s

    supra

    02/04/2021, 8:03 AM
    please help me for this case, I need recursively copy and transform the value form a map to another one, but received Type mismatch error. How to resolve and thanks very much
    private fun transformDepsRecursively(target: Project, from: Map<*, *>, to: MutableMap<*, *>) {
        log.quiet("$TAG transformDepsRecursion start")
        from.forEach {
            val valueFrom = it.value
            var valueTo = valueFrom;
            if (valueFrom is ProjectDescriptor) {
                valueTo = target.project(valueFrom.path)
            } else if (valueFrom is Map<*, *>) {
                valueTo = mutableMapOf<String, Any>()
                transformDepsRecursively(target, valueFrom, valueTo)
            }
            to[it.key] = valueTo
        }
        log.quiet("$TAG transformDepsRecursion end")
    }
    v
    • 2
    • 2
  • e

    etibaldi

    02/04/2021, 10:51 AM
    anybody knows what’s the best way to figure out which dependencies on your 20+ modules android project resolve to just jcenter?
    b
    v
    • 3
    • 8
  • d

    dave

    02/04/2021, 12:53 PM
    Is there a channel here to track issues with 1.4.30? I'm upgrading one of my libraries and am encountering a problem compilation (this happens when I make an inline class constructor private). Just want some advice to see if anyone else here is also experiencing this before raising an issue:
    > Task :values4k:compileTestKotlin FAILED
    e: org.jetbrains.kotlin.codegen.CompilationException: Back-end (JVM) Internal error: wrong bytecode generated
       L0
        LINENUMBER 17 L0
        ALOAD 0
        ILOAD 0
        INVOKESTATIC Money.constructor-impl (I)I
        IRETURN
       L1
        LOCALVARIABLE this LMoney; L0 L1 0
        LOCALVARIABLE value I L0 L1 1
        LOCALVARIABLE $constructor_marker Lkotlin/jvm/internal/DefaultConstructorMarker; L0 L1 2
        MAXSTACK = 2
        MAXLOCALS = 3
    File is unknown
    j
    v
    • 3
    • 12
  • n

    nkiesel

    02/04/2021, 4:14 PM
    I have an question regarding the new "value class" (successor of "inline class") from 1.4.30: it states: "From now on, Kotlin requires the
    @JvmInline
    annotation before a class declaration for the JVM backend". Is that only required for Java compatibility or do I have to add this to all value/inline classes going forward for all my JVM code, even for 100% Kotlin code?
    g
    • 2
    • 1
  • e

    Eugene

    02/04/2021, 5:19 PM
    Hey, Community! 👋 Today we've released Kotlin 1.4.30 :kotlin:. More information about it you can find in this blog post. And precisely this release is essential to us, and hope to you. And here is "Why?". In Kotlin 1.4.30, we've announced the Beta stage of the new JVM IR backed. This article describes what it is and why it's important to enable it. But let me repeat the article's central thesis here: please, switch on the JVM IR backend and build your project. And if you will face any problems, please use the YouTrack link or this Slack channel to submit your concern or ask a question. This version of the JVM backend compiler becomes a default one since 1.5. So, we need to test it very-very well, and for that, we call the Community for this kind of activity. And we hope you will answer our call. With love, Kotlin Team.
    :kotlin-intensifies: 14
    ❤️ 15
    m
    b
    +4
    • 7
    • 11
  • r

    Reinis Muiznieks

    02/04/2021, 5:58 PM
    Hi! Maybe someone here knows a better way to solve issue I have. I have to parse custom byte array into class. I want end class to be immutable. Currently this is my workflow
    private class InternalParamDefinition {
        var id = 0
        var type: Byte = 0
        var defaultValue: Any? = null
    }
    
    object ParamLoader {
        @JvmStatic
        fun load(id: Int, bytes: ByteArray): ParamDefinition {
            fun createInternal(): InternalParamDefinition {
                val param = InternalParamDefinition()
                param.id = id
                val buffer = PacketBuffer(bytes)
    
                while (true) {
                    when (buffer.unsignedByte) {
                        0 -> return param
                        1 -> param.type = buffer.byte
                        2 -> param.defaultValue = <http://buffer.int|buffer.int>
                        3 -> param.defaultValue = buffer.string
                        else -> throw IllegalStateException("unknown field type")
                    }
                }
            }
    
            val internalParam = createInternal()
            return ParamDefinition(
                id = internalParam.id,
                defaultValue = internalParam.defaultValue,
                type = internalParam.type
            )
        }
    }
    I have heard ideas about using Protobuf. Maybe there is some better way to do this?
    e
    • 2
    • 4
  • f

    fitzoh

    02/04/2021, 6:44 PM
    I've got someone that's having issues joining the channel and thinks he's getting caught in a queue, any admins able to give me a hand?
    a
    • 2
    • 1
  • j

    Jason Ankers

    02/05/2021, 4:20 AM
    How can I pass values from a flow obtained inside a function to a flow defined outside of it?
    val publicFlow: Flow<State> = flowOf(..)
    fun doSomething() {
        launch {
            val localFlow = someService.getStream()
            // i want to expose values from localFlow through publicFlow here
        }
    }
    z
    l
    • 3
    • 2
  • a

    andylamax

    02/05/2021, 5:35 AM
    Hello, I am getting
    Class 'tz.co.asoft.IPrinciple' is compiled by an unstable version of the Kotlin compiler and cannot be loaded by this compiler
    using kotlin 1.4.30 JVM/IR
    Class '<http://tz.co|tz.co>.asoft.IPrinciple'
    was compiled by kotlin 1.4.21 JVM/IR. Is this expected? Do all my dependencies need to be recompiled by 1.4.30?
    p
    • 2
    • 3
  • n

    Nikolay Kasyanov

    02/05/2021, 8:19 AM
    Hey folks, I brief question to explicit API mode in 1.4. First of all, it’s really nice, thanks! The question: why does it demand
    public
    modifier for public interfaces’ methods? It’s not like you can type anything else there anyway, looks redundant.
    m
    • 2
    • 2
  • l

    linus muema

    02/05/2021, 10:31 AM
    Hi guys... Is there a way to sort a map/Hashmap using both the keys and values. For instance:
    [Elijah=51, Chloe=144, Natalie=207, Jayden=390, Elizabeth=485, Matthew=485]
    In this map, I would like values to be sorted in a descending order first. Then sort the keys in an alphabetical order. i.e
    Elizabeth
    must appear before
    Matthew
    even though their values are the same. 🤷‍♂️
    n
    m
    i
    • 4
    • 16
  • k

    Kris Wong

    02/05/2021, 4:34 PM
    when calling a
    suspend
    function within
    runBlocking
    , the following code should not be executed until the function completes, correct? I am seeing some flakiness in a test that doesn't make sense to me.
    z
    • 2
    • 1
  • a

    Andy Gibel

    02/05/2021, 6:06 PM
    Hi all - qq about what's possible with Kotlin: Assume I want to convert between two types. One of type
    interface A
    and one of
    interface B
    is there a way to write a generic convert function using 
    inline reified
     that will convert A to B if and only if a conversion function 
    fun(a) : B
      exists?
    m
    n
    • 3
    • 34
  • a

    Ali Albaali

    02/05/2021, 6:53 PM
    Is there a way to enable
    kotlin.result
    in commonMain source set? I tried all the solutions below(in the thread), and it still shows me the error. However it worked on the other targets.
    • 1
    • 2
  • w

    WukongRework.exe

    02/05/2021, 10:28 PM
    I am trying to play around with value and inline classes on the kotlin playground but it has an unresolved reference to the JvmInline annotation, and specifically importing
    kotlin.jvm.JvmInline
    leads to a
    This declaration is only available since Kotlin 1.5 and cannot be used with the specified API version 1.4
    is there a specific way to get this to work in the playground currently?
    a
    e
    i
    • 4
    • 16
  • k

    Kev

    02/06/2021, 6:39 AM
    I have a question which is more design pattern related than Kotlin related (I'm not sure where to even ask this). Say you have an API endpoint
    POST /endpoint
    which requires posted json data to be of a specific json structure. You then mutate this data into something that goes into your database. Where does this mutation take place? On your repository, or something before that and after the endpoint handler?
    :stackoverflow: 4
    t
    • 2
    • 2
  • p

    Philipp Mayer

    02/06/2021, 12:43 PM
    Hello everyone, does one of you remember an article/pdf that basically recommended to use Kotlin, aimed for management? I remember that there was a great write up that lots of people referred to, but I can't find it anymore. Our team already uses Kotlin and I will make a little showcase/intro (30min) for out other IT teams, so also having something ready for management would probably help. Thanks a lot!
    z
    • 2
    • 3
  • h

    Hamza GATTAL

    02/06/2021, 2:44 PM
    Do you talk about Kotlin in Action
    p
    • 2
    • 1
  • p

    poohbar

    02/07/2021, 5:15 PM
    Hey does anyone have any clue what could be going wrong here? Maven ran from the
    maven-wrapper
    fails to compile my project with this error:
    [ERROR] Failed to execute goal org.jetbrains.kotlin:kotlin-maven-plugin:1.4.30:compile (compile) on project my-project: Compilation failure: Compilation failure:
    [ERROR] /Users/poohbar/IdeaProjects/my-project/Controller.kt:[23,30] Unresolved reference: of
    The line that it fails on looks like this:
    val path = Path.of(folder, file)
    And replacing it with:
    val path = Paths.get(folder, file)
    solves the issue. So bizzarre. 😮
    e
    • 2
    • 12
  • a

    Andrew

    02/07/2021, 6:45 PM
    I enabled the new 1.5 experimental features as outlined below using the "compileKotlin" block with language/api verison as 1.5. This works except I get errors on an additional test sourceSet "Task :compileLongTestKotlin FAILED" "Class 'xx' is compiled by a pre-release version of Kotlin and cannot be loaded by this version of the compiler. I had the same issue with my test folder so added "compileTestKotlin" block with the 1.5 options which worked. Adding the same for my additional sourceset results in "Could not find method compileLongTestKotlin()" https://blog.jetbrains.com/kotlin/2021/02/new-language-features-preview-in-kotlin-1-4-30/#sealed-interfaces
    m
    v
    +2
    • 5
    • 7
Powered by Linen
Title
a

Andrew

02/07/2021, 6:45 PM
I enabled the new 1.5 experimental features as outlined below using the "compileKotlin" block with language/api verison as 1.5. This works except I get errors on an additional test sourceSet "Task :compileLongTestKotlin FAILED" "Class 'xx' is compiled by a pre-release version of Kotlin and cannot be loaded by this version of the compiler. I had the same issue with my test folder so added "compileTestKotlin" block with the 1.5 options which worked. Adding the same for my additional sourceset results in "Could not find method compileLongTestKotlin()" https://blog.jetbrains.com/kotlin/2021/02/new-language-features-preview-in-kotlin-1-4-30/#sealed-interfaces
m

Marc Knaup

02/07/2021, 7:23 PM
How do you set language version 1.5 exactly? All source sets and projects that depends on 1.5 code also need to have language version 1.5 set.
a

Andrew

02/07/2021, 7:27 PM
Just with this in build.gradle compileKotlin { kotlinOptions { languageVersion = "1.5" apiVersion = "1.5" } } And then unit tests didn't work until I added compileTestKotlin { kotlinOptions { languageVersion = "1.5" apiVersion = "1.5" } } But now I have a 3rd sourceSet (another type of test) which I can't get to work. This is all the same project/module
v

Vampire

02/07/2021, 7:51 PM
Can you share an MCVE that reproduces your problem? Then it is much easier to maybe see your problem.
i

ilya.gorbunov

02/07/2021, 8:34 PM
You can use the following construction to set
kotlinOptions
for all Kotlin compilations in the project:
tasks.withType(org.jetbrains.kotlin.gradle.dsl.KotlinCompile::class) {
    kotlinOptions { ... }
}
a

Andrew

02/07/2021, 9:14 PM
Is that the kts syntax? I'm not using gradle kts but got it to work with a modified version of that
i

ilya.gorbunov

02/07/2021, 9:18 PM
Yes. In Groovy scripts, you can use the same, just without the
::class
part.
a

Animesh Sahu

02/08/2021, 7:00 AM
You can
tasks.withType<KotlinCompile> { ... }
as well o.O, it'll evaluate configuration block for all the tasks with given type.
View count: 4