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

    LeoColman

    05/19/2019, 5:25 AM
    Hi! Do you have an alternative for
    substringAfter("X")
    where X is a regex? so
    substringAfter(regex)
    t
    • 2
    • 1
  • r

    Rohan Maity

    05/19/2019, 6:44 AM
    Aren't CLion, GoLand not open source ?
    p
    g
    a
    • 4
    • 7
  • m

    mingkangpan

    05/19/2019, 12:04 PM
    Cannot resolve external dependency org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.31 because no repositories are defined.
    Required by:
        project :
    allprojects {
        repositories {
            mavenCentral()
            jcenter()
        }
    }
    
    plugins {
        kotlin("jvm") version "1.3.31"
    }
    ^this is my build.gradle.tks in root folder, what is wrong?
    d
    m
    g
    • 4
    • 9
  • c

    cbruegg

    05/19/2019, 7:50 PM
    Might be a decompiler bug. Can you show the real bytecode here?
    i
    m
    g
    • 4
    • 17
  • c

    Chi

    05/19/2019, 8:12 PM
    is there a function to print out non null array of int in Kotlin?
    [1,2,null]
    will print
    [1,2]
    h
    • 2
    • 1
  • j

    jw

    05/19/2019, 9:00 PM
    Are you on the JVM? You can use
    Objects.hashCode(Object...)
    which will have an intrinsic in Java 13 (provided it ships)
    :trollface: 1
    e
    • 2
    • 2
  • r

    Rohan Maity

    05/19/2019, 11:19 PM
    @hhariri could I DM you ?
    ✔️ 1
    l
    h
    • 3
    • 2
  • m

    Matej Drobnič

    05/20/2019, 8:08 AM
    Language design question: What is the reason for
    const
    keyword existing? Why can't compiler automatically treat all vals that are assigned to constant value (such as string literal or number literal) as
    const
    ? Is there a situation where using
    const
    is not preferred?
    d
    t
    w
    • 4
    • 8
  • t

    thana

    05/20/2019, 9:15 AM
    is there an annotation we can use to mark debug-statements or something, so i get a warning during compile time if there are debug statements in my code left?
    m
    m
    m
    • 4
    • 5
  • j

    joelpedraza

    05/20/2019, 1:27 PM
    Is there some annotation magic I can sprinkle on a val property to signal to the compiler that it’s guaranteed to be immutable (as apposed to only read only). Use case: cross module nullability smart casts
    ➕ 1
    s
    m
    • 3
    • 12
  • f

    Florian

    05/20/2019, 2:21 PM
    If the javac compiler is in the JDK, where is the kotlinc compiler?
    t
    k
    • 3
    • 9
  • f

    Florian

    05/20/2019, 6:40 PM
    Do non-Android Kotlin programs need a JRE to run?
    r
    r
    • 3
    • 9
  • t

    Tristan

    05/21/2019, 2:19 AM
    I’m interested in any discussions/guideliness/efforts around how to write clean and expressive Kotlin. I realise that there’s https://kotlinlang.org/docs/reference/coding-conventions.html but I’m looking more at how we can use a language like Kotlin to make code more readable and make intentions clear in a concise way. Not just syntax and capitalization, but more about what shape your API should have and how you can make it hard to use incorrectly (using static types and using clear naming). I realise that these things aren’t really language specific, but I think it’s fair to say that without putting explicit thought into this, it’s easy to bring over baggage from previous experience (ie. Kotlin that looks like Java). I don’t want to bring up the s-word here (Swift) but I do see that the Swift API Guidelines (https://swift.org/documentation/api-design-guidelines) have been at least partially responsible for that community’s efforts in how to make code clear at the point of use, and to take advantage of the features that language provides (algebraic data types, internal/external parameter names etc) as well as a structured approach to thinking about API design. I’ve been reading a lot about Kotlin from various sources and our team is using it day to day. What I’m looking for is the place that discussions take place, so that my team and I can learn from and participate in them, and also whether there are any community resources/guidelines around how to best use Kotlin in this way.
    👍 3
    t
    • 2
    • 2
  • j

    Jukka Siivonen

    05/21/2019, 9:07 AM
    Why does not IDEA allow (gives warnings) formatting builder chains like this?
    s
    g
    c
    • 4
    • 7
  • p

    pindab0ter

    05/21/2019, 1:17 PM
    Is there a way for a class constructor to return an optional type of itself? I would like the success of the constructor/init to be dependent on whether a network or db call succeeds or not. How would you otherwise handle this? With a factory pattern? Try/catch?
    s
    k
    +2
    • 5
    • 11
  • d

    Darwon Rashid

    05/21/2019, 1:26 PM
    Hello! I am using Ktor framework to build a web app and I am playing around with the built-in jackson content negotiation, I have data classes that I must respond back to the client side using call.respond(status = HttpStatusCode.OK) {return@respond patientList} where patientList is a list<JSONPatient> and JSONPatient is a data class that has nested data classes but it is all primitive types.I keep getting this error message and i can't figure out why. ERROR Application - 307:reportUnresolvedClass - This class is an internal synthetic class generated by the Kotlin compiler, such as an anonymous class for a lambda, a SAM wrapper, a callable reference, etc. It's not a Kotlin class or interface, so the reflection library has no idea what declarations does it have. Please use Java reflection to inspect this class: class com.wallscope.casebook.api.routes.patients.PatientsKt$patients$1$1$2
    k
    • 2
    • 1
  • s

    snowe

    05/21/2019, 2:55 PM
    Is there an equivalent in kotlin to Groovy's
    StringGroovyMethods#getAt(Matcher matcher, int idx)
    method?
    ✅ 1
    h
    • 2
    • 8
  • r

    Ron K

    05/21/2019, 3:46 PM
    Hi, i'm using Kotlin 1.3.31 and just started to check out vaadin for some possible usecases. Vaadin is written in Java and uses Streams instead of Kotlin-Sequences, of course. Now, Docs say, I should use
    Sequence<T>.asStream()
    to make s Stream out of an Sequence, but https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.streams/kotlin.sequences.-sequence/as-stream.html does not seem to be in the Std-Lib anymore!? (Target is JRE 8)
    c
    • 2
    • 3
  • p

    pindab0ter

    05/21/2019, 4:36 PM
    Is there a way to use IntelliJ’s built-in profiler to work with Kotlin? It’s greyed out for me.
    s
    • 2
    • 4
  • x

    xenoterracide

    05/21/2019, 6:41 PM
    I have a list
    1.0, 2.0, 0.0, 1.0, 2.0,0.0, 2.0, 2.0
    , I want 3 lists
    1.0, 2.0
    ,
    0.0, 1.0, 2.0
    ,
    0.0, 2.0, 2.0
    where
    0.0
    is a sort of delimiter (so if I had more of those, it would be in the list to the right. Is there an obvious operation to make this happen?
    s
    • 2
    • 3
  • u

    ushort

    05/22/2019, 2:20 AM
    Hey, question regarding tornadofx. Im creating a view around 100 times and the view is loaded through fxml so its quite slow. I read somewhere that reusing the FXMLLoader can improve performance and was wondering if tornadofx already had some sort of support for that
    s
    • 2
    • 2
  • c

    Chris

    05/22/2019, 8:41 AM
    Are people from the “Kotlin/Everywhere” team in here?
    g
    a
    • 3
    • 3
  • p

    Paul Caswell

    05/22/2019, 9:53 AM
    I just don't understand the difference or why one of them fails.
    Is_this_a_bug_or_a_user_error_.txt
    r
    • 2
    • 9
  • r

    Rok Koncina

    05/22/2019, 3:44 PM
    Hey guys, I'm trying to create a nice structure of states of data I'm getting from the server and I don't know how not to repeat all the constructor parameter(s) for each case? Here's an example where I have to add the parameter
    value: Value
    to the constructor of each subclass. Any idea how to make this nicer? Thanks!
    sealed class BaseStatus(
        open val value: Value?
    )
    
    data class LoadingStatus(
        override val value: Value?
    ) : BaseStatus(value)
    
    data class DoneStatus(
        override val value: Value
    ) : BaseStatus(value)
    
    data class ErrorStatus(
        val error: Throwable,
        override val value: Value?,
        var consumed: Boolean = false
    ) : BaseStatus(value)
    s
    g
    • 3
    • 4
  • j

    jw

    05/22/2019, 3:45 PM
    if you want to pass the data into the constructor, you're going to need to define it in each constructor
    r
    • 2
    • 1
  • g

    gildor

    05/22/2019, 3:47 PM
    You can make
    value
    abstract field instead of constructor property, it's more flexible and less typing
    r
    s
    s
    • 4
    • 14
  • d

    Dico

    05/22/2019, 7:30 PM
    Does anyone have experience configuring proguard to play nice with jackson-module-kotlin? I think I need a way to -keepattributes conditionally (currently I have a
    @KeepMembers
    annotation) Ideally I can keep the kotlin metadata in those classes, or keep the local variable table for constructors so that it will work with Java 8 parameter names module.
    • 1
    • 1
  • l

    louiscad

    05/22/2019, 7:56 PM
    Is there a chance for a tutorial from the community to be integrated on the Tutorials section of Kotlin's website? Are there any rules regarding what is accepted or not, or a process for it?
    e
    h
    n
    • 4
    • 8
  • b

    buremba

    05/23/2019, 11:45 AM
    Isn't it exotic that this code compiles without any issue on Kotlin? 🧐
    Untitled.kt
    🐈 1
    👌 4
    😁 15
    👀 3
    🤣 3
    e
    • 2
    • 5
  • u

    U75957

    05/23/2019, 1:10 PM
    Does Kotlin libraries have function to make cartesian product? like in python https://docs.python.org/2/library/itertools.html#itertools.product
    r
    s
    s
    • 4
    • 7
Powered by Linen
Title
u

U75957

05/23/2019, 1:10 PM
Does Kotlin libraries have function to make cartesian product? like in python https://docs.python.org/2/library/itertools.html#itertools.product
r

Ruckus

05/23/2019, 2:29 PM
list1.flatMap { e1 ->
    list2.map { e2 -> e1 to e2 }
}
s

Stephan Schroeder

05/23/2019, 3:22 PM
now we only need a cartProduct extension function that hides this implementation 😂
s

snowe

05/23/2019, 4:08 PM
you can make a pr to this repo and I should be releasing it soon (if I can get azure devops to cooperate) https://github.com/snowe2010/kotlin-extensions
u

U75957

05/24/2019, 5:58 AM
@Ruckus @Stephan Schroeder what about unknown count of lists? Library implementation should be more universal. Can your implementation works similar like that? https://rosettacode.org/wiki/Cartesian_product_of_two_or_more_lists#Kotlin
@snowe is your library multiplatform? I'm not interested in Kotlin/JVM
r

Ruckus

05/24/2019, 1:53 PM
@U75957 You could rewrite the code I gave to use a producer, though there are concerns with that. If the producers cannot be iterated multiple times, the inner loop won't work. The easy solution to that would be to just collect the two iterables into lists first. If they are too big, a cartesian product is probably not really what you want anyway...
s

snowe

05/24/2019, 3:52 PM
@U75957 I haven't touched multiplatform very much so I'm not sure if it will work. It's just plain kotlin, so I think it should work, but I'm not sure.
View count: 9