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

    Jérémy CROS

    03/09/2021, 3:46 PM
    Hi guys! 🙂 I’m looking to rewrite some of our old Rx code with flow but I just can’t get my head around this one... What I’m looking to do is : collect a flow with a timeout, everytime I collect a value, check if it satisfies a certain condition else keep collecting And I need a way to know if, at the end of the timeout, nothing was collected. I feel like I’m somewhat close with this but it just doesn’t seem to be working like I want 😕
    val result = withTimeoutOrNull(10000L) {
        flowProvider.getFlow().collect {
            if (it.condition) // ALL GOOD, can exit collect and keep going
            else // Not good enough, collect some more and see if I can get a match
        }
    }
    if (result) == null // Assume nothing was collected?
    Is it even feasible this way?
    a
    • 2
    • 2
  • g

    groostav

    03/09/2021, 11:47 PM
    maybe I can open a feature request on the kotlin plugin to flag any set operators on
    Collection<A> op Collection<B> -> Collection<Serializable>
    as suspicious?
    n
    • 2
    • 31
  • d

    Denis Ambatenne

    03/10/2021, 8:36 AM
    Hi all! 👋 We are working to improve the experience of getting started with :kotlin: Kotlin for all newcomers, and we would value your feedback about our latest design. We invite: • experienced backend developers who plan to start using Kotlin or who have recently started using it • mobile developers who plan to start using Kotlin Multiplatform Mobile or who have recently started using it  To participate in a short study. The whole thing won’t take more than an hour. 👉 If you are interested, please fill out this form. With love, Kotlin Team.
    ❤️ 1
    👍 1
    l
    • 2
    • 2
  • m

    matt

    03/10/2021, 11:33 AM
    What are the possible consequences if I ignore ‘Package directive doesn’t match file location’ issue?
    r
    • 2
    • 4
  • v

    Vampire

    03/10/2021, 12:46 PM
    Is there a way in Kotlin to match a regex until some character without creating a substring? Like
    find(input, 50)
    to search after character 50 but so that only until character 50 is tried to match. And what is the difference between
    slice
    ,
    substring
    and
    subSequence
    ?
    e
    • 2
    • 15
  • g

    Gopal S Akshintala

    03/10/2021, 1:19 PM
    Are there any docs/talks about how you sold Kotlin to your team? I am planning to do so at Salesforce and I need a reference for my pitch. Thanks
    👀 2
    c
    o
    • 3
    • 2
  • m

    Manuel Pérez Alcolea

    03/10/2021, 7:46 PM
    I have a class a bit like this:
    class Vector(val x: Double, val y: Double, val z: Double = .0) {
        operator fun div(n: Double) =
            Vector(x / n, y / n, z / n)
    
        fun magnitude() = sqrt(x*x + y*y + z*z)
    
        fun normalized() = when (val m = magnitude()) {
            0.0 -> Vector(x, y, z)
            else -> this / m
        }
    
        // more stuff
    }
    and I want to have another class with most of the same functionality, but more like as a wrapper, where
    x
    and
    y
    are
    Int
    but everything else is computed with `Double`s, and with 2 additional
    Int
    properties
    targetX
    and
    targetY
    . Is there anything in Kotlin that can help me achieve this without writing every method that wraps another method? (or any good idea?) I tried using`by` with an interface to delegate but the types (
    Int
    and
    Double
    ) wouldn't match so it wouldn't work.
    e
    n
    y
    • 4
    • 7
  • l

    Luiz Carlos Arruda Silva

    03/10/2021, 9:43 PM
    Hi guys, live tomorrow. And I want shared with all you:

    https://www.youtube.com/watch?v=4E4v6nEehE0▾

    thanks
    🇵🇹 1
    e
    • 2
    • 1
  • d

    dany giguere

    03/11/2021, 12:48 AM
    hey folks, I’m leaning Spring boot. To begin with I’d like to build a MPA (multi page application), which is just a normal non spa website. What is the be templating engine for spring boot ? One I could insert javascript/vue.js components in it ?
    :stackoverflow: 3
    :google: 5
    n
    a
    • 3
    • 2
  • u

    ursus

    03/11/2021, 4:13 AM
    How do you name your Dao method in kotlin?
    foo(), getFoo(), loadFoo(), findFoo()
    ?
    m
    v
    • 3
    • 6
  • c

    crummy

    03/11/2021, 4:34 AM
    I have a class:
    val c = Array<Int>::class
    I want to get the parameterized type of c (i.e.
    Int
    ). Is this possible on the JVM?
    a
    • 2
    • 6
  • e

    elect

    03/11/2021, 7:23 AM
    is there an easiest/shorter way to drop the
    g
    in a string such as
    v0.1.9-1-g3a259e0
    (which is always "$version-g$commitId") other than using something relying on
    lastIndexOf(-g)
    and then combining the two substrings?
    r
    n
    • 3
    • 11
  • e

    Eugen Martynov

    03/11/2021, 9:28 AM
    What are for
    .kotlin_module
    files are used? I can not open it in IDE unfrotunately
    l
    • 2
    • 8
  • p

    Paul Woitaschek

    03/11/2021, 1:32 PM
    Why does the explicit api mode require me to annotate functions of interfaces with a visiblity? Is anything but public even valid on interfaces?
    j
    p
    +4
    • 7
    • 26
  • m

    Marc Knaup

    03/11/2021, 3:59 PM
    Why isn’t it allowed to pass the constant
    0
    to a
    Double
    ? Why
    0.0
    ?
    p
    z
    r
    • 4
    • 48
  • m

    Manuel Dupont

    03/11/2021, 5:02 PM
    At first, I used to take Result. But, it removes me the possibility to have an exhaustive result sealed class that I can treat in the caller with when keyword. Which is very nice at compile time.
    :thread-please: 2
    n
    m
    +2
    • 5
    • 214
  • r

    Ralph Nader

    03/11/2021, 6:38 PM
    hello, does anyone knows how i can make the user change his picture by pressing on an imageButton without using firebase or so? And is there a way to save the image using shared preferences? (I’ve tried googling it 😅)
    :google: 7
    :stackoverflow: 5
    :android: 2
    r
    a
    • 3
    • 3
  • l

    Luigi Scarminio

    03/11/2021, 10:33 PM
    Hello. I'm using kotlin 1.4.30 in a multi-module project. When I make a change at the code, it seems that Intellij is not compiling the new code. I need to always run gradle clean first, so my changes take effect. Has anyone been thru this before?
    a
    • 2
    • 1
  • p

    Peter Ertl

    03/12/2021, 9:03 AM
    anybody else experiencing index corruption / index issues with kotlin in intellij idea currently? not a single day without purging and recreating the cache 😞
    l
    c
    +3
    • 6
    • 12
  • y

    Yan Pujante

    03/12/2021, 6:19 PM
    I find it very hard to get to the javadoc (or should I say kotlindoc) for kotlin classes. If I go to the kotlinlang website and enter "flow" as a search request, I find articles about flow but not the javadoc.. Is it available somewhere? Is there a magic query that can show me results for only javadoc (not the whole documentation)?
    s
    r
    • 3
    • 4
  • j

    Jason Jackson

    03/12/2021, 10:43 PM
    Is there a way to reduce compile / test cycles like REPL or Hot Reload with Kotlin? only thing I saw is jrebel
    v
    • 2
    • 27
  • p

    pavi2410

    03/13/2021, 6:28 PM
    Has anyone figured out how to mimic Rust's dbg! macro with Kotlin? From Rust docs
    fn factorial(n: u32) -> u32 {
      if dbg!(n <= 1) {
        dbg!(1)
      } else {
        dbg!(n * factorial(n - 1))
      }
    }
    I hope to be able to write something like this in Kotlin
    fun factorial(n: Int): Int {
      if (dbg(n <= 1)) {
        return dbg(1)
      } else {
        return dbg(n * factorial (n - 1))
      }
    }
    Possible incomplete implementation
    fun <T> dbg(expr: T): T {
      println(expr)
      return expr
    }
    Is there any way to capture the expression syntax itself rather than the value?
    d
    y
    +2
    • 5
    • 6
  • v

    Vampire

    03/13/2021, 8:49 PM
    Is there something like
    Function1
    but as consumer, so without return value?
    y
    r
    l
    • 4
    • 7
  • c

    Ch8n

    03/14/2021, 8:32 AM
    Hi Guys! I found
    elementAt()
     function on collections, I started to wonder which one is better for getting values,
    elementAt()
    or
    get()
    .. Found only this line
    element at is useful for collections that do not provide indexed access, or are not statically known to provide one.
    , so does that mean
    elementAt()
    is useful for non-index-based collection? like LinkedList? maps? graphs? Even examples show https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/element-at.html arrays and List sample not other once.. is it because there is only list, set, and map in collections of Kotlin?
    e
    • 2
    • 2
  • v

    v79

    03/14/2021, 9:52 AM
    Random thought - one of things I like about Kotlin is the ability to chuck a bunch of classes and functions into a file during the rapid prototyping phase. Then IntelliJ makes it easy to refactor it into separate files later. Java, so many files being created and renamed and deleted....
    :kotlin-intensifies: 3
    ➕ 3
    s
    j
    • 3
    • 2
  • u

    user

    03/14/2021, 2:03 PM
    message has been deleted
    🎉 9
    g
    j
    c
    • 3
    • 4
  • b

    bjonnh

    03/14/2021, 8:44 PM
    I'm struggling trying to get a modular build to work with a library that doesn't seem to expose a module:
    Exception in thread "JavaFX Application Thread" java.lang.IllegalAccessError: class net.nprod.bcm.separation.PeakSimulatorKt (in module bcm) cannot access class smile.math.special.Erf (in unnamed module @0x4993dace) because module bcm does not read unnamed module @0x4993dace
    • 1
    • 2
  • r

    Ralph Nader

    03/14/2021, 9:40 PM
    Hello, does anyone know how to save the checkbox state and value is fetching data from an api? I stored the data in a List, my recycle view is working, and everything works fine, buthow can I save the checkbox state and the text value so I can print it in a grid view in another page? I am using kotlin
    v
    • 2
    • 5
  • n

    nkiesel

    03/15/2021, 5:11 PM
    Is there a nice way to define a list of extension functions? Background: in one of our user group discussions we discussed various ways to code "replace or add" for lists. We then wanted to test all of the proposed solutions using a `listOfProposals.forEach { f -> ... }`but could not find a way to define such a list. The best I have right now is to use a list of non-generic anonymous functions, where each item calls one of he proposed solutions. But that does not look "nice":
    fun <T> List<T>.replaceOrAdd1(item: T, predicate: (T) -> Boolean): List<T> { ... }
    fun <T> List<T>.replaceOrAdd2(item: T, predicate: (T) -> Boolean): List<T> { ... }
    data class Person(val name: String, val age: Int, val email: String, val address: String = "")
    val listOfProposals = listOf(
        fun(list: List<Person>, person: Person, predicate: (Person) -> Boolean) = list.replaceOrAdd1(person, predicate),
        fun(list: List<Person>, person: Person, predicate: (Person) -> Boolean) = list.replaceOrAdd2(person, predicate),
    )
    // <https://pl.kotl.in/GvbQWnFEq> is the link to the working example
    n
    y
    +2
    • 5
    • 122
  • x

    xii

    03/15/2021, 7:06 PM
    when doing mockmvc tests with result matchers, is it possible to check the shape of a json object response?
    • 1
    • 2
Powered by Linen
Title
x

xii

03/15/2021, 7:06 PM
when doing mockmvc tests with result matchers, is it possible to check the shape of a json object response?
what i mean is, is it possible to check shape instead of comparing to a json object? kind of like its done in typescript
i'm thinking about iterating keys and checking that they have the strings expected, but maybe there's a better way
View count: 2