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

    Big Chungus

    07/26/2020, 1:20 PM
    Why is new IDEA no longer showing gradle sourceSet dependencies on MPP projects?
    👀 3
    l
    a
    • 3
    • 2
  • w

    weber de lima santos

    07/26/2020, 7:24 PM
    What you guys think about Kotlin and its frontend "branch"? I'm already into kotlin/server, but i don't feel kotlin/js as solid in terms of: jetbrains plans, community, etc, as kotlin/server or kotlin/mobile...
    a
    g
    • 3
    • 6
  • w

    WillP

    07/27/2020, 4:27 AM
    Hey guys, first time posting here. What is the best channel to ask a multiplatform/cinterops question?
    s
    r
    • 3
    • 2
  • u

    user

    07/27/2020, 1:03 PM
    Kotlin 1.4.0-RC Released We’re almost there! We’re happy to unveil Kotlin 1.4.0-RC – the release candidate for the next major version of our programming language. Read on to learn about what has changed in Kotlin 1.4.0-RC, and make sure to try its new features before they are officially released with Kotlin 1.4.0. A special thanks to everyone who […]
    🎉 42
    :kotlin: 12
    :kotlin-flag: 5
    n
    b
    c
    • 3
    • 3
  • d

    David Alford

    07/27/2020, 6:03 PM
    Question: I've used Delegates.observable and Delegates.vetoable several times. Is there a way to get both (such that I get a callback before and after the value changes)? If not, what would be the recommended alternative?
    z
    • 2
    • 1
  • r

    Robert Jaros

    07/27/2020, 7:24 PM
    Is there a way to force all Kotlin versions to 1.4 in Gradle? Even if there are libraries used, that were compiled with 1.3.72? I'm getting the following warning:
    w: Runtime JAR files in the classpath should have the same version. These files were found in the classpath:
        /opt/rjaros/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib/1.3.72/8032138f12c0180bc4e51fe139d4c52b46db6109/kotlin-stdlib-1.3.72.jar (version 1.3)
        /opt/rjaros/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib-common/1.4.0-rc/4f17246362f6cbcf924f199a06619a4f77b51335/kotlin-stdlib-common-1.4.0-rc.jar (version 1.4)
    w: Some runtime JAR files in the classpath have an incompatible version. Consider removing them from the classpath
    but also compiler errors, which probably are caused by this incompatibility:
    Caused by: java.lang.NoSuchMethodError: kotlin.sequences.SequencesKt.flatMapIterable(Lkotlin/sequences/Sequence;Lkotlin/jvm/functions/Function1;)Lkotlin/sequences/Sequence;
            at org.jetbrains.kotlin.resolve.calls.components.CollectionTypeVariableUsagesInfo.getDependentTypeParameters(ResolutionParts.kt:342)
    h
    • 2
    • 1
  • r

    Robert Jaros

    07/27/2020, 10:40 PM
    This artifact https://repo1.maven.org/maven2/org/jetbrains/kotlin/kotlin-scripting-compiler-impl-embeddable/1.4.0-rc/kotlin-scripting-compiler-impl-embeddable-1.4.0-rc.pom has dependency on
    kotlinx-coroutines-core
    1.3.7
    which makes my project classpath a mess with both 1.3 a 1.4 Kotlin versions. Is it a bug? Any way to workaround?
    h
    • 2
    • 2
  • j

    Jilles van Gurp

    07/28/2020, 10:17 AM
    I'm trying to build a simple library with a github action that publishes jar files for js and jvm to a maven repository. I've so far tried jitpack and the github package repository and have had issues with both. With jitpack, it actually publishes something and I can see from the jitpack logs it generates js and jvm versions of the jar. My problem is I can't seem to figure out how to add the jvm version as a dependency. Here's an example oss project for which I tried to publish a jar: https://github.com/jillesvangurp/geogeometry. When I try to add the published jvm jar as a dependency, it instead pulls in the js version and then that doesn't work because it's not a js project. I think jitpack just randomly picks a jar that it keeps instead of publishing the -js and -jvm versions which is what I would expect. With the github package repository where I tried to do something similar, I get weird http errors. I've managed to publish a non multiplatform project to that before. I'd prefer to use that as this is a private project and I want to publish jars for internal use only.
    > Task :publishJvmPublicationToGitHubPackagesRepository FAILED
    FAILURE: Build failed with an exception.
    16 actionable tasks: 16 executed
    
    * What went wrong:
    Execution failed for task ':publishJvmPublicationToGitHubPackagesRepository'.
    > Failed to publish publication 'jvm' to repository 'GitHubPackages'
       > Could not PUT '<https://github.com/formation-res/FormationSchemaModel/formation-res/FormationSchemaModel-jvm/0.1-SNAPSHOT/maven-metadata.xml>'. Received status code 422 from server: Unprocessable Entity
    I'm currently looking at the articact repository in Google cloud as another option. But before I go there, which package repositories actually work properly with the multi platform plugin? I'd be interested in people that have successfully published multiplatform library jars anywhere. This is kind of crucial to me because I want to reuse some code across web, jvm, and ultimately android & ios as well.
    • 1
    • 1
  • k

    KayCee

    07/28/2020, 10:20 AM
    Hi guys, there is a line of code that I could't guess what it is, when ClassA.( ) what will happen?
    typealias CompletionBlock<T> = UseCase.RequestBlock<T>.() -> Unit
    RequestBlock<T> class is like this:
    class RequestBlock<T> {
        private var onSuccess: ((T) -> Unit)? = null
        private var onFail: ((ErrorModel, CallableImp) -> Unit)? = null
        private var onFinally: (() -> Unit)? = null
    
        fun onSuccess(block: (T) -> Unit) {
          onSuccess = block
        }
    
        fun onFail(block: (ErrorModel, CallableImp) -> Unit) {
          onFail = block
        }
    
        fun onFinally(block: () -> Unit) {
          onFinally = block
        }
    
    
        operator fun invoke(result: T) {
          onSuccess?.invoke(result)
        }
    
        operator fun invoke(error: ErrorModel, apiCallable: CallableImp) {
          onFail?.invoke(error, apiCallable)
        }
    
        operator fun invoke() {
          onFinally?.invoke()
        }
      }
    o
    • 2
    • 1
  • i

    igor.wojda

    07/28/2020, 10:42 AM
    Hey Kotlin team - I want to clarify Kotlin logo colouring guidelines (current guidelines are only referring to “Kotlin” text colour
    Do not display the word Kotlin using any different stylization, color, or font from the surrounding text
    ) What are your thoughts on using black Kotlin logo?
    a
    h
    a
    • 4
    • 4
  • n

    Nir

    07/28/2020, 2:38 PM
    Does Kotlin have a nice way to "chain" two sequences? That is, return a sequence that first goes through the elements of the first sequence, then of the second. The closest thing I see is flatten, which I could make work, but it's intended for sequences of sequences, not simply 2 (or 3, etc) sequences that I already have as separate variables
    s
    • 2
    • 6
  • h

    henrikhorbovyi

    07/28/2020, 4:34 PM
    I just created a project using gradle + Kotlin JS and I want to use File class from Kotlin Jvm
    z
    • 2
    • 7
  • n

    Nir

    07/28/2020, 8:14 PM
    In Kotlin, there's a bit of an issue where even if you have something like this:
    data class Foo(val bar: List<T>)
    Despite the use of both val and List (as opposed to MutableList), it's still pretty easy to mutate data out from underneath Foo. I was curious how many people had felt the need to have some kind of true immutable list type, to prevent this scenario? One pleasant surprise in Kotlin was that I was able to implement something reasonable in just a handful of lines. Even just:
    class ImmutableList<T> private constructor(val data: List<T>) : List<T> by data {
        constructor(x: Sequence<T>) : this(x.toList())
        constructor(x: Iterable<T>) : this(x.toList())
    }
    
    operator fun<T> ImmutableList<T>.plus(x: Sequence<T>) = (data.asSequence() + x).toImmutableList()
    operator fun<T> ImmutableList<T>.plus(x: Iterable<T>) = (data + x).toImmutableList()
    operator fun<T> ImmutableList<T>.plus(x: T) = plus(sequenceOf(x))
    
    fun <T> immutableListOf(vararg elements: T) = elements.asIterable().toImmutableList()
    fun <T> Sequence<T>.toImmutableList() = ImmutableList<T>(this)
    fun <T> Iterable<T>.toImmutableList() = ImmutableList<T>(this)
    Is already pretty usable (thanks mostly to delegation). And now we can go back to our previous example:
    data class Foo(val bar: ImmutableList<T>)
    This is actually conditionally immutable depending on the T (say it's an Integer or String). I'm curious if many people are using things similar to this? Or are people just living with the possibility of unexpected mutations in Foo, finding it not too big of a problem?
    z
    b
    m
    • 4
    • 14
  • n

    Nir

    07/29/2020, 4:47 AM
    Suppose I want, in a certain scope, to use my own map function instead of the standard library one. How do I do that?
    z
    • 2
    • 2
  • r

    Robert Jaros

    07/29/2020, 7:46 AM
    Is it possible to play with coroutines on https://play.kotlinlang.org?
    p
    • 2
    • 2
  • f

    frank

    07/29/2020, 8:30 AM
    What differences are there between Kotlin SDK and JDK?
    a
    • 2
    • 1
  • p

    Philipp Mayer

    07/29/2020, 1:36 PM
    Hey guys, does anyone have a hint what I did wrong here?
    var email: String? = "default"
            set(value) {
                field = setEmail(value)
            }
    
        fun setEmail(value: String?): String? {
            val emailRegex = Regex("^\\w+([-+.']\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*\$")
            val isValidEmail = value != null && emailRegex.matches(value)
            return if (isValidEmail) value else null
        }
    The shown field is part of a representation of an old legacy db, which might has a "wrong" email adress in it. Its set by jpa, but I would like to perform the shown operation when the field is set to filter out "wrong" emails. The function is tested and is returning the correct result. However, email is always set as "default". What did I do wrong here? Thanks ahead!
    n
    m
    +2
    • 5
    • 20
  • e

    Edoardo Luppi

    07/29/2020, 2:23 PM
    Hi! How do I link to an external URL in the `@see`tag in documentation?
    z
    • 2
    • 1
  • n

    Nicholas Bilyk

    07/29/2020, 3:18 PM
    I'm trying out 1.4-RC and I'm having a problem with intellisense on build.gradle.kts files They compile and reload fine, but the IDE doesn't pick up the JDK and I get red highlights on everything such as java.lang.Object
    a
    • 2
    • 1
  • n

    Nir

    07/29/2020, 3:52 PM
    How do I use delegation on a member that I don't want to declare in the primary constructor?
    n
    • 2
    • 35
  • n

    Nir

    07/29/2020, 4:43 PM
    Am I missing an obvious reason why there's a mapNotNull but no associateNotNull?
    m
    • 2
    • 5
  • i

    Ian

    07/29/2020, 4:46 PM
    I've created a project with a relatively simple
    build.gradle.kts
    file: https://gist.github.com/sanity/b89e7d1be5cfd6779e0186f929b45333 But for some reason a number of JVM packages aren't on my classpath, particularly anything in the 
    java.util.concurrent
     package, am I missing something from my build file?
    i
    • 2
    • 4
  • n

    Nezteb

    07/29/2020, 4:55 PM
    I’ve been trying to figure out how to specify the signature of a generic function when it’s used as an argument to a higher order function. I’m looking at a function that tries to compare some arguments of unknown type.If they can be cast to numbers, it compares them as numbers.  If they are strings, it compares them as stings. It’s possible to write one of these for each compare, of course, but the casting logic is duplicated. It would be nice to factor that out using a higher order function:
    compareOp(v1: Any, v2: Any, f: (Any, Any) -> Boolean): Boolean
    ...
    compareOp(v1, v2, {x, y -> x < y})
    This isn’t quite right though. The “<” on the last line doesn’t compile. Any < Any doesn’t exist. Since I’m only trying to compare as strings or numbers, it’s possible to write this as:
    compareOp(v1: Any, v2: Any, fs: (String, String) -> Boolean, fd: (Double, Double) -> Boolean): Boolean
    ...
    compareOp(v1, v2, {x, y -> x < y}, {x, y -> x < y})
    That works, but still doesn’t feel right. {x, y -> x < y} is duplicated. I should be able to pass it in just once. Its signature is:  <T> fun comparison(x: Comparable<T>, y: T): Boolean As far as I can tell, it’s not possible to stick this type parameter in the signature of compareOp. I tried making an interface Comparison<T> with an “operator fun invoke” that has the Comparable<T> signature. That still doesn’t quite work. compareOp has to specify a single explicit value for T. Has anyone solved this sort of issue?
    s
    • 2
    • 2
  • n

    Nicholas Bilyk

    07/29/2020, 5:05 PM
    What's the new dependency for kotlinx serialization for RC1? I see that coroutines has changed from kotlinx-coroutines-core-common and specific platforms to just kotlinx-coroutines-core, but implementation("org.jetbrains.kotlinx:kotlinx-serialization-runtime:1.0-M1-1.4.0-rc") doesn't seem to work...
    j
    • 2
    • 9
  • n

    Nir

    07/29/2020, 8:09 PM
    The only way I can think of is to have a private class Key at file scope, and then the class in question can members that accept a Key. Seems a bit hacky though.
    s
    m
    • 3
    • 34
  • j

    jeggy

    07/29/2020, 8:40 PM
    Does anyone have any good tips to get the very best performance out of IntelliJ? I have a Desktop with 32 cores and 64 GB RAM and would love to just give IntelliJ the right configuration so it would be incredibly fast. 😛
    z
    h
    +3
    • 6
    • 9
  • b

    bbaldino

    07/29/2020, 11:10 PM
    Has anyone else seen constant "updating indices"/`Analyzing...` in files since updating to intelllij 2020.2? I've restarted intellij but it's still going. All day.
    a
    • 2
    • 5
  • k

    kevin.cianfarini

    07/30/2020, 3:29 AM
    What's the best way to instantiate a constant ULong/UInt value that's out of Long/Int range?
    String.toULong
    ?
    i
    c
    • 3
    • 4
  • n

    Nicholas Bilyk

    07/30/2020, 2:20 PM
    Did kotlin serialization runtime get pulled from bintray? Yesterday org.jetbrains.kotlinx:kotlinx-serialization-runtime-js:1.0-M1-1.4.0-rc worked and today it doesn't... https://dl.bintray.com/kotlin/kotlin-eap/org/jetbrains/kotlinx/
    s
    • 2
    • 6
  • r

    ReddyTintaya

    07/30/2020, 5:09 PM
    Hi, i'm doing an e commerce with the backend in spring and for recipes i'm returning mimeMessage emails but i'm building my htmls as strings dynamically, so it's a hard string process ... is there any library that you've used and recommend for doing this?
    b
    • 2
    • 2
Powered by Linen
Title
r

ReddyTintaya

07/30/2020, 5:09 PM
Hi, i'm doing an e commerce with the backend in spring and for recipes i'm returning mimeMessage emails but i'm building my htmls as strings dynamically, so it's a hard string process ... is there any library that you've used and recommend for doing this?
b

Big Chungus

07/30/2020, 5:19 PM
#kotlinx-html
r

ReddyTintaya

07/30/2020, 5:20 PM
thanks
View count: 3