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

    mjthornton

    04/14/2020, 5:36 PM
    Hey! I want to get array[0].. But I want to ensure that the array is at least size >= 1 In Kotlin, is there an easy way / shortcut to do this? [10:36 AM] Instead of doing if( array.size() > 0){ … } [10:36 AM] If not, you could probably make an extension function
    s
    53 replies · 2 participants
  • m

    mjthornton

    04/14/2020, 7:37 PM
    Hey! Is there a built-in way of determining if an int falls within a number range?
    Untitled.kt
    a
    s
    7 replies · 3 participants
  • d

    dumptruckman

    04/14/2020, 7:40 PM
    I need to create a list of all the `m`’s produced by this cartesian product. Is there a nice idiomatic way to do this? Am I missing some kind of built in cartesian product function?
    messages.forEach { message ->
                recipients.forEach { recipient ->
                    val m = messagingService.recordMessage(message, listOf(recipient))
                }
            }
    m
    h
    +3
    8 replies · 6 participants
  • p

    pniederw

    04/15/2020, 3:16 AM
    Does Kotlin method delegation really break whenever a default implementation is added for a method of the delegated-to Java interface? Suddenly the default implementation instead of the delegate's implementation is called. As far as I can tell, my Kotlin code broke simply by updating to a new JDK version that adds default implementations to existing interfaces.
    m
    k
    3 replies · 3 participants
  • u

    user

    04/15/2020, 9:39 AM
    message has been deleted
    🎉 12
    t
    m
    +1
    6 replies · 3 participants
  • s

    Sam Garfinkel

    04/15/2020, 4:30 PM
    Is there a way to get a
    KType
    from an
    Any
    (or the corresponding KClass<*>) or am I stuck with only having access to the
    KClass<*>
    ?
    z
    7 replies · 2 participants
  • а

    Александр Васильев

    04/15/2020, 4:42 PM
    Hello. I am using 1.4-M1 with worksheets script (.ws.kts). Is it the right channel to talk about worksheets Intellij feature?
    m
    a
    2 replies · 3 participants
  • j

    Jiri Bruchanov

    04/15/2020, 7:53 PM
    anyone who would know, why following code fails because of type inference ?
    s
    z
    12 replies · 3 participants
  • m

    mjthornton

    04/15/2020, 8:15 PM
    Is there a more succinct way of doing this in Kotlin?
    Untitled
    s
    b
    +2
    31 replies · 5 participants
  • a

    Andrey Stepankov

    04/15/2020, 10:32 PM
    Does kotlin have any way to generate random unique id in compile time. I mean id is random, but is const for runtime? So i can write compiler plugin, but may be community already has solution. For example: // sourse fun a(): String = CompileTimeId.nextId() // compiled code fun a(): String = "hdhdjdnwld"
    c
    s
    26 replies · 3 participants
  • p

    Paul Woitaschek

    04/16/2020, 6:35 AM
    I.e.
    abstract class ReceiverClass {
    
     open fun String.onSomethingHappened(){
       println(this)
     }
    }
    
    class Child  : ReceiverClass(){
    
      override fun String.onSomethingHappened() {
        super.onSomethingHappened() <-- doesnt compile
        println("hello world")
      }
    }
    s
    k
    7 replies · 3 participants
  • f

    fatih

    04/16/2020, 7:27 AM
    Is it a bad practice to have lambda inside lambda?
    (String) -> (() -> Unit)
    Or is there any side effects?
    s
    t
    3 replies · 3 participants
  • y

    yawkat

    04/16/2020, 9:01 AM
    Anyone know if this is in the tracker yet or even fixed in newer releases? https://play.kotlinlang.org/#eyJ2ZXJzaW9uIjoiMS4zLjYxIiwiY29kZSI6InByaXZhdGUgaW5saW5lIGZ1biBmKGNyb3NzaW5saW5lIGNpOiAoKSAtPiBVbml0KSA9IG9iamVjdCA6IFIoKSB7XG4gICAgb3ZlcnJpZGUgZnVuIGcoKSB7XG4gICAgICAgIGNpKClcbiAgICB9XG59XG5cbnByaXZhdGUgdmFsIHByb3AgPSBmIHt9XG5cbm9wZW4gY2xhc3MgUiB7XG4gICAgb3BlbiBmdW4gZygpIHt9XG59XG5cbmZ1biBtYWluKCkge1xufSIsInBsYXRmb3JtIjoiamF2YSIsImFyZ3MiOiIiLCJqc0NvZGUiOiIifQ==
    i
    2 replies · 2 participants
  • a

    Ahmed Mourad

    04/16/2020, 10:09 AM
    Which one would you go for: 1. Implementing your repository/manager directly
    interface Manager { ... }
    
    class ManagerImpl(...) : Manager {
    
        override fun functionality(): SomeShenanigans {
            return Shenanigans.create { ... }
        }
    
        ...
    }
    2. Dividing implementation into multiple small functions
    interface/typealias Functionality: () -> SomeShenanigans
    
    fun functionalyImpl(): SomeShenanigans = Shenanigans.create { ... }
    
    class ManagerImpl(f: Functionality, ...) : Manager {
    
        override fun functionality(): SomeShenanigans {
            return f.invoke()
        }
    
        ...
    }
    The former is much more compact but can cause circular dependencies and would require some weird shenanigans to solve, while the later solves the issues with circular dependencies but would require much more boilerplate.
    t
    a
    8 replies · 3 participants
  • s

    Slackbot

    04/16/2020, 10:15 AM
    This message was deleted.
    d
    a
    2 replies · 3 participants
  • s

    spand

    04/16/2020, 12:31 PM
    For library authors
    As creating new libraries is vital for the Kotlin ecosystem, we keep improving the experience of library authors. The new library authoring mode will help shape your code in the way that's best for stable APIs. Also, we are going to release Dokka 1.0 to support docs generation for all platforms.
    From https://blog.jetbrains.com/kotlin/2019/12/what-to-expect-in-kotlin-1-4-and-beyond/ Can one read about this anywhere ?
    i
    1 reply · 2 participants
  • s

    spand

    04/16/2020, 2:14 PM
    Say I have a method called as
    .method(true)
    or
    .method(false)
    . I would like to migrate that to
    .method(SortOrder.ASC)
    and
    .method(SortOrder.DESC)
    respectively. Can I do that with
    @Deprecated
    or something similar that can be triggered on an entire project? (I can easily end up with
    .method(if(true) SortOrder.ASC else SortOrder.DESC)
    but I would like to automate the final step)
    c
    n
    2 replies · 3 participants
  • d

    David Winer [G]

    04/16/2020, 5:12 PM
    gRPC Kotlin launched today — check out the docs at grpc.io to try it out! Shout out to @Brent Shaffer and the rest of the team that worked on this
    🎉 12
    z
    4 replies · 2 participants
  • m

    mjthornton

    04/16/2020, 6:16 PM
    Hey guys, I’m looking for some recommendations/advice! I’m trying to automate code standards for my project…. First want to do simple things such as: • Check the top of the file to ensure it has a copyright + specific comment format • Enforce Kdoc/JavaDoc format for our functions I would like it to either Flag Bitbucket PR’s or reject builds if they do not comply I’ve already used File Templates & Live Templates… But this acts more of an aid instead of actually enforcing standards My current thinking is to use Android Lint and tie it to gradle to fail builds if they don’t comply, but I haven’t really researched this approach yet… • Starting to read up KTlint
    s
    12 replies · 2 participants
  • p

    Peter

    04/16/2020, 7:07 PM
    hi, new to kotlin and playing with inline classes as a replacement for value classes
    inline class TypesafeId<T>(val id: Int)
    
    typealias PersonId = TypesafeId<Person>
    data class Person(val id: PersonId)
    
    typealias AnimalId = TypesafeId<Animal>
    data class Animal(val id: AnimalId)
    
    fun main(args: Array<String>) {
      println(Animal(AnimalId(1)))
      // println(Person(AnimalId(1))) typecheck fails at compile time 
      println(Person(TypesafeId(1)))
    }
    wondering why the last
    println
    compiles successfully?
    z
    d
    3 replies · 3 participants
  • v

    voben

    04/16/2020, 7:34 PM
    are these 2 expressions equivalent in kotlin? assuming var start = 0
    start += 1  // expr1
    start++    // expr2
    s
    d
    5 replies · 3 participants
  • r

    rrva

    04/17/2020, 10:35 AM
    I have a fairly large kotlin backend app, 14 KLOC, 1.3.70, gradle-based. If I want to improve compile times for edit->compile->run in IntelliJ, where do I start (using IntelliJ:s built-in compiler, 2020.1)
    m
    k
    3 replies · 3 participants
  • s

    spand

    04/17/2020, 12:18 PM
    My project seems to no longer finish compilation after bumping a dependency. Is there a compiler option or something that shows which file the compiler is currently compiling to narrow the problem down ?
    1 reply · 1 participant
  • k

    kushalp

    04/17/2020, 2:48 PM
    I am trying to use the better-parse library to parse a file. The file has the following structure:
    Header
    LineItem
    LineItem
    Footer
    I have written a
    Grammar<T>
    to parse each line of each "type" so far, e.g.
    Grammar<Header>
    . How can I compose these grammars together? The lines are split by newline.
    k
    8 replies · 2 participants
  • a

    Ananiya

    04/17/2020, 5:04 PM
    this code
    fun generate(){
        println("${randomWord()}${randomKey()}${randomWord()}${randomWord()}${randomKey()}${randomWord()}${randomSymbol()}${randomWord()}${randomSymbol()}")
    }
    prints
    String Int String String Int String Char String and Char
    respectively and how do i make this code to change it place randomly in every run that can be
    String  String Int String Int Char String Char String
    t
    j
    +1
    5 replies · 4 participants
  • n

    no

    04/18/2020, 11:02 AM
    kinda a lazyweb question, but i couldn’t find a very good kotlin solution. what’s the best way to find the union of a set of intervals. for example: given: [1,3], [2,5], [8,9] result is: [1,5], [8,9]
    j
    n
    9 replies · 3 participants
  • c

    carlos cdmp

    04/18/2020, 6:30 PM
    Hello, is there any elegant way to define a sealed class of data classes with common vals?
    a
    1 reply · 2 participants
  • o

    Ofir Bar

    04/18/2020, 7:52 PM
    Hey guys, using Gson, I made a generic method that performs a deep copy on an object.
    inline fun<reified T> Any.deepCopy(): T {
        val JSON = Gson().toJson(this)
        return Gson().fromJson(JSON, T::class.java)
    }
    However, when I try to perform this Deep Copy on a List, the items on the list are
    LinkedTreeMap
    . Can anyone correct me as what can I possible do to resolve it?
    d
    j
    +1
    12 replies · 4 participants
  • l

    Ludwig Groeber

    04/19/2020, 10:45 AM
    I’m a student currently writing his bachelors thesis about a DLT Application in M&A. I’ve decided to build a simple but working prototype to facilitate the Q&A Process on the Corda Ledger. (which is simply exchanging text in a verified manner) Problem is: I have no prior coding experience (no java, no kotlin, but I’m doing Kotlin as it seems easier) and only very roughly understand the code and what it does. So basically an absolute noob. I need to have a working prototype ready by next week Friday as the dealine is approacing fast. I was hoping to find someone who can guide me on how to build it and help me find solutions. So if there is any volunteer out there who wants to help a struggling student, please contact me. I can really use the help. 🙂 I would need someone to check my kotlin code and explain a counple of things to me… Cheers, Ludwig
    d
    z
    5 replies · 3 participants
  • v

    vishesh

    04/19/2020, 7:07 PM
    I am an experienced mobile application developer. Knows Kotlin, Swift, Dart and Java. I want to learn Server Side development suggest me a framework to start with. Thank You.
    a
    a
    +2
    6 replies · 5 participants
Powered by Linen
Title
v

vishesh

04/19/2020, 7:07 PM
I am an experienced mobile application developer. Knows Kotlin, Swift, Dart and Java. I want to learn Server Side development suggest me a framework to start with. Thank You.
a

Alejandro Rios

04/19/2020, 7:08 PM
You can ask in #ktor
👍 1
a

Amiedema

04/19/2020, 7:34 PM
https://alpas.dev
👍 2
i

Ihar S

04/19/2020, 8:00 PM
Let’s be honest, Spring is the most used jvm based framework on the market at the moment and it supports kotlin as well
💯 2
v

vishesh

04/19/2020, 8:26 PM
Yes, Its true. Thinking to start my journey with Ktor. Once I will get familiar with the basics. Will decide next.
m

Mike

04/20/2020, 11:52 AM
If it's for future employment, then Spring, Ktor, maybe Micronaut or Quarkus. If it's for 'fun', and to learn about HTTP/GRpc/REST/GraphQL/whatever else, then pick a lighter weight framework, OR if you really want to get deep, look at what these frameworks use under the covers. Spring, and other frameworks, are very productive because they hide a lot of stuff, and auto-configure, and... but like any framework, when things go wrong, it can be much harder to figure out why...
👍 1
v

vishesh

04/20/2020, 11:57 AM
@Mike I wanna to learn for fun... Seems right way to go about it
View count: 5