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
getting-started
  • r

    Ruckus

    04/18/2018, 8:46 PM
    @Max Deineko Folding without an initial value is called reduce: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/reduce.html
  • k

    Karolo

    04/18/2018, 10:56 PM
    so its not getting started totally but can u recommend any sources to master kotlin for android development, i know some advanced topics of kotlin - to not write java style - but find it hard to apply in everyday coding. Thanks in advance
    👍 1
    s
    k
    3 replies · 3 participants
  • z

    zucen.co

    04/19/2018, 9:31 AM
    i want to use when expression in this kind of situation
    when(string){
       null -> ...
       this.length>1 -> ...
       else ->
    }
    i resorted to this:
    when{
       this==null -> ...
       this.length>1 -> ...
       else ->
    }
    is this idiomatic solution?
    :yes: 1
    m
    a
    +1
    22 replies · 4 participants
  • a

    Andreas Sinz

    04/19/2018, 7:34 PM
    e.g.
    map.getOrPut(key, { mutableSetOf() }).plusAssign(value)
    ❤️ 1
    d
    8 replies · 2 participants
  • t

    thatadamedwards

    04/19/2018, 7:38 PM
    @Fuyang what do you think?
    f
    1 reply · 2 participants
  • o

    otakusenpai

    04/20/2018, 4:37 PM
    hello, can someone help me with this error? https://pastebin.com/C5bHMaTq
    :stackoverflow: 1
    p
    1 reply · 2 participants
  • n

    Nico Smeenk

    04/21/2018, 12:46 AM
    hello - I have a question - can I use a Map with generics simmilar to that in kotlin?
    val objects = FXCollections.observableHashMap<KClass<A: BasicModel>, ObservableList<A: BasicModel>>()
    
    inline fun <reified T: BasicModel> get(): ObservableList<T> {
        return objects[T::class]
    }
    k
    5 replies · 2 participants
  • d

    dave08

    04/22/2018, 2:34 PM
    Hi guys! Is there any way of to implement
    invoke
    operator to initialize an
    enum class
    ? I tried as an extension function, but the Intellij doesn't seem to see the constructor...
    k
    5 replies · 2 participants
  • n

    Nirav Tukadiya

    04/23/2018, 5:37 AM
    Can anyone suggest few vidoes for getting started?
    g
    h
    +2
    9 replies · 5 participants
  • m

    marstran

    04/24/2018, 12:51 PM
    Either that or
    (A.firstOrNull() ?: B.first()).field
    . Or just split it into two lines:
    val first = A.firstOrNull() ?: B.first()
    val field = first.field
    ➕ 6
    a
    2 replies · 2 participants
  • r

    Robert Menke

    04/24/2018, 1:04 PM
    lol glad you clarified the spelling 😛
    d
    2 replies · 2 participants
  • m

    morganbovi

    04/24/2018, 4:56 PM
    variable?.run{ }
    == run this block if this thing is not null? correct?
    ✔️ 1
    r
    1 reply · 2 participants
  • r

    rellenberger

    04/24/2018, 6:14 PM
    can Delegates be used to observe changes like RxJava, or Googles LiveData?
    a
    1 reply · 2 participants
  • m

    Mathias Brandt

    04/25/2018, 11:28 AM
    Hello 🙂 Pretty new to Kotlin here. I have defined an interface in Kotlin that has a method with a
    Long
    return type. I am implementing the interface in a Java class, and I would like the return type to be
    Long
    , but it says it has to be
    long
    . How can I accomplish this? 🤔
    a
    k
    2 replies · 3 participants
  • h

    heyzoos

    04/25/2018, 1:22 PM
    Hullo! I'm trying to make use of the
    javax.script
    support that was introduced in Kotlin 1.1, however the first line always throws a
    NullPointerException
    .
    val engine = ScriptEngineManager().getEngineByExtension("kts")!!
    engine.eval("val x = 3")
    println(engine.eval("x + 2"))  // Prints out 5
    I'm extremely new to this language and its tooling, is there something obvious I'm missing? I was under the impression that it would sort of just "come with" the language but I wouldn't be surprised at all if I need to install a dependency or two. My google skills have been failing me unfortunately.
    p
    2 replies · 2 participants
  • i

    igorvd

    04/25/2018, 2:39 PM
    the only way of having backing properties is doing something like this?
    class C {
        private val _elementList = mutableListOf<Element>()
    
        val elementList: List<Element>
             get() = _elementList
    }
    m
    1 reply · 2 participants
  • e

    ebonet

    04/26/2018, 1:02 PM
    what would be the use case of apply here? (actually curious)
    d
    s
    7 replies · 3 participants
  • u

    0rph3u

    04/26/2018, 6:55 PM
    hey, can someone clarify this line on @antonioleiva’s site: "First thing to clarify is that MVP is not an architectural pattern" enerywhere i have seen it's called an architectural pattern...
    a
    3 replies · 2 participants
  • n

    Nztom

    04/26/2018, 10:58 PM
    Hi All. Do any of you know of some good resources to get up and running with Kotlin? My last experience with the JVM was at University, that was Java 6. Now we are at Java 10 o.o. I am a Web guy, I use mostly Python, PHP and Go at work so I am spoilt when it comes to the simplicity of creating HTTP/JSON/RESTish apis. My understanding is that the 'Spring' framework is used for web dev? But it seems to be a 6000 pound gorilla for a hello world api...is there something like the equivilent of golangs net/http library for Kotlin/Java? any help would be much appreciated.
    t
    k
    +3
    9 replies · 6 participants
  • w

    wilyarti

    04/28/2018, 2:14 PM
    This forks the heavy stuff into another thread allowing the UI to update... The only trouble it the CommonPool can't access the UI or update/change it...
    u
    1 reply · 2 participants
  • o

    ohwelp

    04/28/2018, 7:58 PM
    Hey guys, which testibg framework would you choose right now? Im familiar with junit but heard about spek lately - is it as straight forward as junit 5 is? Maybe something else is worth a shot?
    n
    3 replies · 2 participants
  • c

    crazdrms

    04/30/2018, 2:23 AM
    fun getStringLength(obj: Any): Int? { //
    obj
    is automatically cast to
    String
    on the right-hand side of
    &&
    if (obj is String && obj.length > 0) { return obj.length } return null } Why is it Int here?
    s
    a
    6 replies · 3 participants
  • m

    marlin

    05/01/2018, 1:58 PM
    If I don't do the flatmapelements method it performs as the java code. Only the flatmapelements produce errors.
    a
    9 replies · 2 participants
  • m

    Mathias Brandt

    05/01/2018, 2:41 PM
    Android: I am attaching the same
    textChangedListener
    to multiple input fields. Currently I have this:
    withdraw_input.textChangedListener {
        afterTextChanged {
            validateInput()
        }
    }
    
    reg_number.textChangedListener {
        afterTextChanged {
            validateInput()
        }
    }
    I cannot figure out how to extract the listener to a variable and then re-use it, instead of defining the same listener multiple times. I guess it’s just a syntax issue 🤔 Any hints? 🙂
    k
    39 replies · 2 participants
  • b

    bjonnh

    05/01/2018, 6:25 PM
    any recommended xml parsing library for kotlin?
    n
    4 replies · 2 participants
  • j

    Jamie Huson

    05/01/2018, 8:16 PM
    such as
    if(isNull(someString)) { someString.length } else { someString.length }
    , the first
    someString.length
    would give an error or something
    a
    7 replies · 2 participants
  • k

    karelpeeters

    05/01/2018, 9:57 PM
    Makes sense, the interfaces really are defined in common, but the classes are all
    expect
    .
    i
    b
    6 replies · 3 participants
  • k

    karelpeeters

    05/02/2018, 12:22 AM
    @bjonnh I'm on a JVM project and I can only import interfaces from that package.
    b
    3 replies · 2 participants
  • l

    leosan

    05/02/2018, 11:55 AM
    #SWIFT
    enum NumberCategory {
       case Small
       case Medium
       case Big
       case Huge
       init(number n: Int) {
        if n < 10000 { self = .Small }
        else if n < 1000000 { self = .Medium }
        else if n < 100000000 { self = .Big }
        else { self = .Huge }
       }
    }
    How I can achieve something like this in kotlin? Just to illustrate my problem I have a bunch of business logic conditionals that I want to convert to a type and send it to my view, I’m not even sure if this is the best solution or I stick with boolean methods
    b
    e
    12 replies · 3 participants
  • k

    karelpeeters

    05/02/2018, 11:57 AM
    Create a normal enum, in the companion object put a function
    fromNumber
    or something like that.
    👍 1
    b
    1 reply · 2 participants
Powered by Linen
Title
k

karelpeeters

05/02/2018, 11:57 AM
Create a normal enum, in the companion object put a function
fromNumber
or something like that.
👍 1
b

benleggiero

05/03/2018, 2:51 AM
Even better, put a
operator fun invoke
in the companion object!
View count: 5