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

    Big Chungus

    02/07/2021, 7:50 PM
    Given recent panic with jcenter shutdown, I've started thinking that it'd be nice if jetbrains could come to some sort of partnership with google and endorse google package registry as official kotlin registry. Given that main use case for kotlin is still android development i think it would make a lot of sesnse for both companies. Furthermore, I'm not sure that tying kotlin to "legacy" technology such as maven is the most future-proof way to go. I'd like to hear what JB and the community thinks about the idea.
    👎 1
    ➖ 1
    r
    v
    +12
    • 15
    • 75
  • r

    Rodrigo Graciano

    02/07/2021, 8:34 PM
    Hello. What's the right channel to ask about Kotlin scripts. main.kts extension to be more specific
    w
    • 2
    • 2
  • h

    Henrik Johansson

    02/08/2021, 7:46 AM
    What do I have to do to make integration tests run? I have followed https://docs.gradle.org/current/userguide/java_testing.html#sec:configuring_java_integration_tests but I think it may have to do with me using Kotest. The tests run just fine in Intellij but not using gradle.
    g
    • 2
    • 3
  • s

    Stephan Schroeder

    02/08/2021, 11:00 AM
    So sealed interfaces are coming (https://blog.jetbrains.com/kotlin/2021/02/new-language-features-preview-in-kotlin-1-4-30/#sealed-interfaces) with
    Kotlin 1.5 removes both constraints: you can now make an interface sealed. The subclasses (both to sealed classes and sealed interfaces) should be located in the same compilation unit and in the same package as the super class, but they can now be located in different files.
    Now my question is, can you still extend a sealed interface in a TestCase (within the same module)? Do the tests within a Gradle
    test
    -folder belong to the same sourceSet (and therefore compilation unit?) as the sources under
    src
    ?
    s
    e
    m
    • 4
    • 9
  • s

    spand

    02/08/2021, 1:36 PM
    How do I specify
    kotlinOptions
    in gradle for sourcesets other than
    main
    and
    test
    ? I have problems setting the `languageVersion`/`apiVersion` for my
    testFixtures
    sourceset
    a
    • 2
    • 2
  • r

    Rasmit Devkota

    02/08/2021, 6:37 PM
    Hey, I'm trying to use a @Serializable annotation on a data class for decoding JSON from a string, but it looks like the annotation isn't being applied because it gives this error:
    kotlinx.serialization compiler plugin is not applied to the module, so this annotation would not be processed. Make sure that you've setup your buildscript correctly and re-import project.
    When I add "org.jetbrains.kotlin.plugin.serialization" to the plugins though, it gives me different errors which I don't really understand:
    java.lang.IllegalStateException: Backend Internal error: Exception during code generation
    . For reference, this is in a Jetpack Compose Desktop app, if that has anything to do with the issue. Anyone know the problem?
    d
    • 2
    • 5
  • u

    ursus

    02/08/2021, 7:49 PM
    I found certain cases where when using method reference, IDE screetches to a halt If I change it to a lambda, then it works fine where should I report this?
    e
    • 2
    • 4
  • d

    dMusicb

    02/09/2021, 1:28 AM
    Question regarding withContext; perhaps we're using it incorrectly We are injected some thread context into the call and running a block of code with that injected thread context, so something like
    withContext(InjectThreadContext(...)) {
        //doStuff
        //otherStuff
        //moreStuff
    }
    So this works in the sense that when the coroutine resumes/starts it'll inject our thread context and right after it suspends we have it restore the original context by closing our injected context. But once we reach the end there is no suspend again so the injected context then leaks out of the block whereas we want it to do like a final close. Is there a different method we should be using?
    g
    • 2
    • 3
  • a

    Andrew

    02/09/2021, 10:37 AM
    Hey 👋 Anyone having issues using
    when
    expressions? I keep getting a warning telling me it should be exhaustive but I have every possible branch filled in? I am only seeing this after updating the Kotlin plugin in Android Studio to 1.4.30
    s
    s
    +3
    • 6
    • 20
  • m

    mending3

    02/09/2021, 12:16 PM
    what is kotlin equivalent of Java's
    charAt
    ?
    m
    • 2
    • 1
  • i

    igor.wojda

    02/09/2021, 12:41 PM
    I must admit my mind was blown 🤯 Who can explain to me what’s exactly is going on here?
    😍 5
    d
    m
    +4
    • 7
    • 10
  • j

    Joel

    02/09/2021, 5:01 PM
    Are the 1.4.30 / 1.5 inline (value) classes backed by Valhalla or is it compiler shenanigans under the hood?
    r
    • 2
    • 5
  • m

    mending3

    02/09/2021, 5:02 PM
    update: this is my code:
    build.gradle
    application {
        // Define the main class for the application.
        mainClass = 'translator.AppKt'
    }
    
    task myExecTask(type: JavaExec) {
        classpath = sourceSets.main.runtimeClasspath
        main = 'translator.AppKt'
        args project.getProperty('myFirstArgument') + ' ' + project.getProperty('mySecondArgument');
    }
    gradle myExecTask -PmyFirstArgument=foo -PmySecondArgument=bar
    got error:
    Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 1 out of bounds for length 1
    --------------------------------------------------------------- how do I pass multiple arguments to gradle? this doesn't work
    gradle run myfirstargument mysecondargument
    :stackoverflow: 2
    :google: 3
    m
    v
    • 3
    • 14
  • m

    marzelwidmer

    02/09/2021, 6:21 PM
    Hello
    Koliners
    I want ask about
    SecurityByDesign
    if there better setup how to create the classes https://gist.github.com/marzelwidmer/6aa9733c919f2a8dc6aa84116fe4a580 what I don’t like is…
    invoke
    function is available
    data class Customer (val firstName: FirstName, val lastName: LastName, val gender: Gender)
    // Domain Primitive
    data class FirstName private constructor(val value: String) {
        companion object {
            // Create Object
            operator fun invoke(value: String) = FirstName(validate(value = value))
            private fun validate(value: String): String {
                check(value.isNotEmpty()) { "value must be non-empty" }
                check(value.trim().length >= 2) { "wrong value length" }
                check(value.trim().length <= 20) { "wrong value length" }
                return value
            }
        }
    }
    n
    d
    m
    • 4
    • 22
  • t

    Travis Griggs

    02/09/2021, 7:38 PM
    Suppose you did a lot of "here's a ubytearray, i need to pad it up to certain length with a value", what (if any) extension would you add? I'm not a fan of methods that take two integers, because you lose some safety due to the fact that it's easy to misguess the order of the parameters.
    m
    j
    +2
    • 5
    • 15
  • m

    mending3

    02/10/2021, 5:06 AM
    what is Kotlin equivalent of this Java's code:
    str.charAt(str.length() -1) == ' '
    t
    r
    • 3
    • 2
  • g

    Grigorii Yurkov

    02/10/2021, 7:53 AM
    I do not understand why casting
    this
    to
    S
    is unchecked. Is it a bug or I miss something
    n
    n
    +3
    • 6
    • 14
  • a

    Aaron nerostarx

    02/10/2021, 11:02 AM
    Hello everyone, i wanted just to know, Is there any way i can use kotlin multiplatform mobile on windows??
    v
    j
    • 3
    • 2
  • s

    Sourabh Rawat

    02/10/2021, 12:35 PM
    How can I use
    Result<T>
    from Java code? My interface returns
    Result<T>
    . i am seeing
    Object
    instead of
    Result<T>
    😕
    v
    y
    • 3
    • 3
  • s

    Slackbot

    02/10/2021, 12:41 PM
    This message was deleted.
    :stackoverflow: 1
    m
    • 2
    • 1
  • n

    nickheitz

    02/10/2021, 1:20 PM
    Hi all...Just started getting this message in IDEA community after upgrading to kotlin 1.4.30
    '@JvmOverloads' annotation cannot be used on constructors hidden by inline class rules
    The class in question seems straightforward
    class AudioClassifyWorkflowParameters @JvmOverloads constructor(...
    I'm not clear how to interpret the error, as I don't know what "hidden by inline class rules" is referring to. Any insight appreciated.
    m
    a
    • 3
    • 5
  • t

    Travis Griggs

    02/10/2021, 4:36 PM
    Let's say I wanted to add a little endian encoding API to unsigned integers (UByte, UShort, UInt, ULong) that looked something like:
    anInt.le.ubytes
    . In Swift, I'd accomplish this with something like: protocol LittleEndianEncodable { var byteSize:UInt get() var le:LittleEndianEncoder get() } extension LittleEndianEncodable { var le:LittleEndianEncoder<Self> { return LittleEndianEncoder(self) } } struct LittleEndianEncoder { var value:LittleEndianEncodable var ubytes:Data { // well, Data in Swift return 0..<self.value.byteSize.map { index in self.value >> (index * 8 ) & 0xFF } } } Or something close to that. Then I'd just add an extension to the existing int classes and be off to the races. But in Kotlin, I can't create a new interface that I then enforce on existing class types. Is there an alternate approach to do this? Basically I want
    le
    to return a "trampoline" object which can return the
    ubytes
    for the object it's wrapped, and do it generically, so I don't have to make individual transformer types for each uint type. I looked through the docs, hoping to find that there was already something that answers the byte size for int types, but didn't see anything 😞
    d
    a
    n
    • 4
    • 15
  • g

    Grigorii Yurkov

    02/10/2021, 7:18 PM
    Why is this forbidden?
    m
    c
    +2
    • 5
    • 16
  • n

    nkiesel

    02/10/2021, 9:02 PM
    I have a question about "exhaustive when expression": if I have an enum value which is guaranteed not to have a specific value, the compiler still insists on a branch for that value. Is there a way to avoid that? Concrete simplified example (which does not compile unless I uncomment the one commented out line):
    import kotlin.random.Random
    
    enum class Priority { LOW, MEDIUM, HIGH }
    
    fun main() {
        val priority = Priority.values()[Random.nextInt(Priority.values().size)]
    
        val s1 = when (priority) {
            Priority.LOW -> 1
            Priority.MEDIUM -> 2
            Priority.HIGH -> 3
        }
    
        val s2: Int
        if (priority == Priority.LOW) {
            s2 = 1
        } else {
            s2 = when(priority) {
    //            Priority.LOW -> throw IllegalStateException()
                Priority.MEDIUM -> 2
                Priority.HIGH -> 3
            }
        }
    
        println("s1=$s1 s2=$s2")
    }
    e
    n
    • 3
    • 5
  • a

    Animesh Sahu

    02/11/2021, 3:48 AM
    Is there any differences between kapt, ir plugin, and ksp (kotlin symbol processing)? 🤔
    👍 1
    t
    z
    • 3
    • 3
  • m

    Max Härtwig

    02/11/2021, 9:43 AM
    Hi everyone! I'm new here and I've just started to work with Kotlin and Arrow Meta. Is there a way to see the compiler plugin's stdout in the console when compiling it with gradle?
    println
    doesn't seem to show up...
    s
    • 2
    • 2
  • d

    David Martinez

    02/11/2021, 10:44 AM
    Hi all! I'm new here and I'm assessing the capabilities of Kotlin when working in the Big Data and Data Science fields. Any suggestions? Thanks!
    t
    • 2
    • 1
  • h

    Henrik Johansson

    02/11/2021, 11:48 AM
    Is it only possible to send on a channel from a coroutine? What if I have regular code that produces something that I want to send to a work pool for example how do I do that?
    n
    • 2
    • 2
  • p

    partap

    02/11/2021, 11:52 AM
    I want to make an application using kotlin as a backend. Please help
    🤯 3
    m
    • 2
    • 1
  • a

    ahmad abas

    02/11/2021, 12:07 PM
    as a backend developer that is trying to learn android dev and kotlin, what is the best place to start?
    a
    • 2
    • 1
Powered by Linen
Title
a

ahmad abas

02/11/2021, 12:07 PM
as a backend developer that is trying to learn android dev and kotlin, what is the best place to start?
a

Ali Albaali

02/11/2021, 12:37 PM
You can start learning kotlin here
View count: 6