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

    Daniel

    06/05/2021, 7:56 PM
    I'm really confused by how to share code I write in kotlin with the world. The only guides I can find for publishing kotlin libraries are for multiplatform. It seems like I need to pick a repository and have totally different gradle code for each. Is there some way to do this that doesn't take hours?
    e
    k
    +2
    • 5
    • 30
  • l

    LastExceed

    06/06/2021, 3:45 PM
    why cant a
    data class
    be
    open
    ?
    e
    k
    +2
    • 5
    • 10
  • p

    Prateek Tiwari

    06/07/2021, 4:23 AM
    Hi everyone, I want to read from android datastore, inside the viewModel or repository and want that value available at the time of initialising viewModel. Can anyone suggest a good approach. Thanks
    :not-kotlin: 7
    k
    • 2
    • 4
  • j

    Javier

    06/07/2021, 10:23 AM
    I am trying to set as private the constructor of inline classes (and value classes, I tried both), but I am getting an exception. Is it not supported yet?
    m
    • 2
    • 11
  • r

    Ranjan Rukhaya

    06/07/2021, 10:42 AM
    I need to download pdf file from url and store in internal storage of app..any pointers ?
    k
    • 2
    • 1
  • f

    Fanilog

    06/07/2021, 6:05 PM
    Hello 👋, quick question about data mapping? What would you use to map an object (eg: a
    RemoteUser
    received by a backend to a
    User
    object used by the business logic inside an app)? I used to do it via Interface + Implementation
    interface IUserMapper {
        fun remoteToEntity(remote: RemoteUser): User
    }
    , what is the real benefit than doing it directly with an extension function ?
    fun RemoteUser.toUser() = 
    ...
    (except mocking) 🤔
    ➕ 1
    g
    • 2
    • 1
  • y

    y9san9

    06/07/2021, 6:13 PM
    Hello guys! Have the following issue: I want to track any change in my Map to notify a callback later, and what I did for now (this is just a rush attempt, so the solution may be bad): The map impl: https://pastebin.com/G5HK9jE6 The list impl: https://pastebin.com/ViKrnJQ2 (used in the map
    values
    ) The set impl: https://pastebin.com/zfHS0KZc (used in the map
    keys
    ,
    entities
    ) I hope there is a proper solution, and you can say what I'm doing wrong (or maybe this is the only way)
    r
    j
    • 3
    • 6
  • p

    Peter

    06/07/2021, 6:29 PM
    does anyone know if it’s possible to get a reference to the KClass of a generic type parameter? eg.
    inline fun <reified T>test() { typeOf<T>()... }
    r
    • 2
    • 2
  • m

    magnumrocha

    06/08/2021, 11:03 AM
    is anyone having problem with the
    kotlin.Result
    class?
    k
    c
    • 3
    • 8
  • s

    Stephan Schroeder

    06/08/2021, 12:44 PM
    I'll have to write a pretty basic Annotation Processor (generating a documentation file checking all the classes in the project for special annotations). I understand that there's old KAPT and new (alpha-state) KSP. So normally I'd say, I'll have to use KAPT because KSP is still alpha, but is KAPT maybe equally unstable at the moment, because the Kotlin Compiler Frontend is being reworked? If that's the case I'd probably pick the more modern KSP and update my Processor whenever there's a breaking change (because I don't expect this to be much work given the simple nature of what I need it to do). Are there any educated guesses of when KSP and KAPT (should it be currently unstable) will become stable?
    d
    • 2
    • 1
  • n

    Norbert Sziráczki

    06/08/2021, 2:16 PM
    Hey guys! I'm having some problems with frozen objects on iOS, but only upon upgrading some dependencies. Any ideas? https://youtrack.jetbrains.com/issue/KTOR-2799
    t
    • 2
    • 2
  • v

    Viet Nguyen Tran

    06/08/2021, 3:39 PM
    I have Android Studio 4.2.1 on Mac M1, AVD with arm64 CPU. I cannot run this AVD. How should I do? thank you.
    :not-kotlin: 2
    z
    a
    • 3
    • 5
  • g

    glenkpeterson

    06/08/2021, 8:58 PM
    How come I can write:
    val file = File("hello.txt")
    return when {
        file.isFile -> Or.good(file)
        else        -> Or.bad(chapter.fileName)
    }
    But if I try to capture the
    when
    subject in a variable like this:
    return when(val file = File("hello.txt")) {
        file.isFile -> Or.good(file)
        else        -> Or.bad(chapter.fileName)
    }
    I get, "Incompatible Types: Boolean and File" on the
    file.isFile
    part? The end of this section makes it look like I should be able to do this: https://kotlinlang.org/docs/control-flow.html#when-expression
    d
    e
    n
    • 4
    • 10
  • j

    jean-paul

    06/09/2021, 9:07 AM
    Hey folks, I have just launched the Brussels Kotlin User Group, I would be grateful if you could connect me with people managing DevRel at Kotlin. see https://jiraguha.github.io/brussels-kotlin-user-group/
    c
    • 2
    • 2
  • s

    Slackbot

    06/09/2021, 9:58 AM
    This message was deleted.
    c
    • 2
    • 1
  • b

    Big Chungus

    06/09/2021, 10:01 PM
    Just curious if there's any timeline for new kotlin branding "refactoring"? Slack logo here (and kotlin emojis) are still under old brand.
    i
    • 2
    • 3
  • f

    Fung.Yam

    06/10/2021, 8:52 AM
    Kotlin have new feature of sealed class in 1.5.0, which we can extend sealed class within the same package, maybe now we can implement
    package private
    with sealed and protected?
    g
    • 2
    • 2
  • s

    Saiedmomen

    06/10/2021, 11:41 AM
    requireNotNull
    does not provide smart cast null safety. Is there another way to concisely mark null as Illegal state and have smart cast?
    private var id: Long? = null
    
    override fun delete() = runBlocking {
        requireNotNull(id)
        notesRepository.deleteNote(id!!) // id is not smart cast to not null
    }
    h
    p
    n
    • 4
    • 8
  • p

    Piotr Krzemiński

    06/10/2021, 11:47 AM
    is there some summary page about bugs in Kotlin? in particular I'm interested in bug increase over time e.g. after major version bumps, and how the speed of new bugs appearing relates to the speed of fixing them 😅 YouTrack is public so I could glue some nifty query and dashboard myself, but maybe someone has already done it?
    e
    • 2
    • 3
  • e

    Erik

    06/10/2021, 2:25 PM
    https://play.kotlinlang.org/hands-on/Introduction%20to%20Coroutines%20and%20Channels/ does not load for me. The page loads, but remains blank. Is it just me? (kotlinlang.org docs about coroutines link to there)
    h
    • 2
    • 3
  • c

    Ch8n

    06/10/2021, 7:01 PM
    Hi does anyone know how to create float ranges? I want to get random values between 1.0 to 1.5 for my use case
    b
    • 2
    • 1
  • p

    Patrick Ramsey

    06/10/2021, 8:52 PM
    What’s the correct way to signal that a property getter failed to execute? I know kotlin prefers sealed class result types to exceptions, but I can’t think of another good way to communicate to the caller that a property getter failed except to return null, which isn’t always a good option.
    c
    z
    • 3
    • 13
  • u

    uli

    06/11/2021, 6:54 AM
    Hi all, I need to initialize a
    ByteArray
    with hex literals. Here is my Approach:
    val key = intArrayOf(0x80, 0xFF, 0x00, 0x7f).map { it.toByte() }.toByteArray()
    And the result is (and should be):
    -128,-1,0,127
    Is there a more compact/idiomatic way to do that?
    g
    e
    c
    • 4
    • 12
  • l

    LastExceed

    06/11/2021, 8:25 AM
    anyone else sometimes feeling the urge do wrap strings with value classes so that e.g. in a
    UserProfile
    class
    email
    and
    about_me
    are different types ? I know its overkill but i cant help it
    a
    d
    +4
    • 7
    • 14
  • m

    Mitch

    06/11/2021, 8:45 AM
    Is -Double.MAX_VALUE guaranteed to give the smallest finite negative Double?
    :yes: 1
    a
    s
    h
    • 4
    • 8
  • d

    Dominaezzz

    06/11/2021, 11:51 AM
    Is there a (cheap, i.e no list allocations) way to get the size of a range? Like
    (1..5).size
    ?
    h
    i
    • 3
    • 6
  • b

    blakelee

    06/11/2021, 7:42 PM
    Can someone try adding 370.1 + 0.1 and see if you get 370.2? If it is, try this
    val x = 370.1
    x + 0.1
    I'm getting 370.20000000000005 on a few different Kotlin versions
    ✅ 1
    a
    e
    e
    • 4
    • 17
  • s

    Slackbot

    06/11/2021, 8:28 PM
    This message was deleted.
    e
    • 2
    • 1
  • g

    glenkpeterson

    06/11/2021, 11:12 PM
    I want to write a function that takes an intersection type, but I don't know the syntax (or if it's possible in Kotlin). Here's what I'd imagine using a single ampersand like so:
    // Error here ---v
    fun <T : Slugged & BaseModel> suggestSlug(
        tempSlug: String,
        clazz: Class<T>,
    ): String
    I want to make sure the class passed to this function implements
    Slugged
    (to be sure it has a
    .slug
    property) and extends the abstract class
    BaseModel
    (to be sure it has an
    .id
    property and is a database
    @Entity
    class - I'm using Ebean). I found this, which shows the set-theory, but doesn't show the syntax I need (I apologize if I am misunderstanding any of this): https://kotlinlang.org/spec/type-system.html#intersection-types Should I just make an abstract
    SluggedBaseModel
    ? I'd rather not because abstract vars annotated
    @Column
    need to be initialized and this should be a non-null required constructor parameter for each entity bean that uses it.
    z
    c
    r
    • 4
    • 7
  • t

    TheDukerChip

    06/12/2021, 6:49 AM
    Hey guys, I was looking for Kotlin Chess Engine with AI Player capabilities for play with computer option So far I was only able to find this Cortlandd/KotlinChess If you guys know any other libraries, Kindly suggest that
    k
    s
    • 3
    • 5
Powered by Linen
Title
t

TheDukerChip

06/12/2021, 6:49 AM
Hey guys, I was looking for Kotlin Chess Engine with AI Player capabilities for play with computer option So far I was only able to find this Cortlandd/KotlinChess If you guys know any other libraries, Kindly suggest that
k

Kirill Grouchnikov

06/12/2021, 7:30 AM
You'd probably be better off finding something well established and doing Kotlin bindings to it
t

TheDukerChip

06/12/2021, 7:38 AM
You mean like pick an established and well-maintained library in Java for this use case and bind it in my kotlin code?
k

Kirill Grouchnikov

06/12/2021, 8:26 AM
Is it important to you what is the language that the library is written in? Start with what you actually need - the level of quality and feature set of a chess engine. And then figure out the Kotlin bindings part.
➕ 1
t

TheDukerChip

06/12/2021, 9:49 AM
Okay got your point Thanks for that ⚡
s

Stephan Schroeder

06/14/2021, 6:12 AM
https://github.com/simon-void/voidchess I wrote a chess engine and ui arround it: https://github.com/simon-void/voidchess But some architectural decission makes it very slow compared to other engines. If you're doing a complete search than max search depth is basically 3. I assume it's ELO rating to be around 1800
View count: 16