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

    ziad

    01/19/2018, 5:16 PM
    Modifying a map in a data class, is the following a sound approach?
    data class MyDataClass(
            val myMap: Map<Int, String> = mapOf()
    )
    
    fun addElementToMyDataClass(myInstance : MyDataClass, key : Int, value : String): MyDataClass {
        val mutableCopyOfMap = myInstance.myMap.toMutableMap()
        mutableCopyOfMap[key] = value
        return myInstance.copy(myMap = mutableCopyOfMap)
    }
    j
    n
    • 3
    • 6
  • c

    cy

    01/19/2018, 5:24 PM
    val fullTariffList = arrayOf("customer", "reseller", "vendor").flatMap { type ->  testTariffList.map { it.copy(type = type) } }
    :kotlin: 1
    ➕ 1
    m
    r
    n
    • 4
    • 12
  • k

    katien

    01/19/2018, 8:39 PM
    it's part of kotlintest
    p
    • 2
    • 7
  • v

    vlad

    01/19/2018, 11:00 PM
    can default function arguments be lazily computed expressions?
    i
    • 2
    • 1
  • c

    cedric

    01/19/2018, 11:07 PM
    Not without turning them into a lambda
    v
    • 2
    • 1
  • y

    Yash Jahit

    01/19/2018, 11:37 PM
    @Shawn I dont mean to hurt nor disrespect anyone. If i am wrong then ill admit it. If you think i did ask for the code, then i am sorry to anyone. Its just..anyway personal problems. Sorry again
    s
    • 2
    • 3
  • a

    akritrime

    01/20/2018, 6:48 AM
    Hey I am a noob learning Kotlin and I don't know Java. Can someone help me understand the difference between sealed classes and enums? Am I right in assuming enums are like singleton sealed classes?
    n
    f
    • 3
    • 5
  • s

    shawwn

    01/20/2018, 9:16 AM
    It will only take about 60 seconds
    s
    r
    o
    • 4
    • 3
  • e

    elect

    01/20/2018, 10:20 AM
    how to check if an
    ArrayList<Long>
    is in ascending order? Something available in stlib?
    o
    i
    • 3
    • 3
  • t

    tipsy

    01/20/2018, 11:16 AM
    i have a pretty long questions about the different ways of calling a java method from kotlin, so i'm going to nest it into a thread
    k
    • 2
    • 8
  • f

    fabricio

    01/20/2018, 11:25 AM
    when (obj) {
        null -> println("is null")
        else -> println("is not null")
    }
    I couldn't figure out how to check for not null instead.. is that possible? like
    !null ->
    😄
    k
    • 2
    • 2
  • l

    Les

    01/20/2018, 11:41 AM
    I was looking at Kotlin source. I found code
    contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) }
    Where does
    contract
    come from? What does this code do?
    k
    j
    • 3
    • 3
  • p

    phantom

    01/20/2018, 3:41 PM
    one question, why does javascript has .jsx, typescript .tsx, but kotlin has no react support like .ktx?
    👍 2
    👎 1
    s
    • 2
    • 2
  • d

    Dmitry Kandalov

    01/20/2018, 10:50 PM
    Is there a way to call extension function with fully qualified name?
    r
    • 2
    • 2
  • a

    alexcouch

    01/21/2018, 11:37 AM
    I have a question about local variables. So since you can declare a local variable without an initializer which basically makes them marked with lateinit by default right? And if it doesn't have nullability, and when I try to use it after init'ing it with a conditional, (like the example below), and then I wanna try using it afterwards, then, even tho it's not nullable, it, by default, is null right? And if that's the case, then how can I check if it is init'd even though it's nonnull? Here's an example:
    fun ArrayList<ItemStack>.tick(){
        var emptyStack: ItemStack
        for(stack in this){
            if(emptyStack == null) {
                if (stack.isEmpty) {
                    emptyStack = stack
                }
            }
        }
    }
    k
    • 2
    • 11
  • a

    Ayden

    01/21/2018, 12:20 PM
    Does Kotlin allows us to use the code like this?
    // numberList: 1, 2, 3, 4, 5, 6
    
    numberList.contains(1,2,6)
    k
    • 2
    • 5
  • a

    amanda.hinchman-dominguez

    01/21/2018, 4:16 PM
    @Ruckus but it allows you to use Java types as well, which does present a risk for nullable types
    r
    g
    • 3
    • 2
  • r

    Ruckus

    01/21/2018, 4:21 PM
    You could do
    int("whatever") ?: default
    a
    • 2
    • 4
  • f

    fabricio

    01/21/2018, 5:44 PM
    can anyone help me understand
    .let .also .apply etc
    extension methods?
    :google: 1
    n
    s
    • 3
    • 3
  • o

    Olekss

    01/21/2018, 7:00 PM
    so is there whay how to get from Method to Function1 ?
    i
    • 2
    • 1
  • p

    pablisco

    01/21/2018, 8:02 PM
    Didn't know where to ask this. O was looking at the code for the Kotlin Conf app and I don't see how the iOS app uses the code from
    Common
    is there any blog post or guide on how it works?
    g
    • 2
    • 3
  • d

    dave08

    01/22/2018, 8:12 AM
    What's the accepted practice for not found situations in repos and apis? Say I have
    userRepo.getUser(userId)
    and it wasn't found, should it return null, throw a domain exception (NoUserFoundException) or have a sealed class with a null object? (I'm using coroutines, not Rx...)
    👍 1
    s
    c
    +4
    • 7
    • 62
  • b

    bj0

    01/22/2018, 11:29 PM
    set doesn't return a value, why not just
    set(value) { baz.bar = value }
    ?
    b
    • 2
    • 1
  • r

    Ruckus

    01/22/2018, 11:48 PM
    @benleggiero I think what you are looking for is the elusive "just do what I mean" operator. I heard they're adding it to JavaScript.
    b
    s
    • 3
    • 5
  • r

    raulraja

    01/22/2018, 11:57 PM
    But where does
    baz
    come from?
    b
    • 2
    • 1
  • a

    aoriani

    01/23/2018, 1:26 AM
    How much compatible Kotlin generics are with Java ?
    sealed class NetworkResource<out ResponseType, out ErrorType> {
        class Loading<out ResponseType, out ErrorType> : NetworkResource<ResponseType, ErrorType>()
        data class Success<out ResponseType, out ErrorType>(val response: ResponseType) : NetworkResource<ResponseType, ErrorType>()
        data class Error<out ResponseType, out ErrorType>(val error: ErrorType) : NetworkResource<ResponseType, ErrorType>()
    }
    
    class NetworkObserver<ResponseType, ErrorType> : Observer<NetworkResource<ResponseType, ErrorType>> {}
    When I use it from Java I'm getting
    incompatible types: <anonymous NetworkObserver<Object,String>> cannot be converted to Observer<NetworkResource<Object,String>>
    . However if I am remove
    out
    from NetworkResource it works for Java, but it messes type inference in Kotlin.
    • 1
    • 1
  • a

    alexanderUV

    01/23/2018, 6:06 AM
    is there a kotlin-native channel? I don't see one
    u
    • 2
    • 2
  • e

    edwardwongtl

    01/23/2018, 10:32 AM
    And the compiler knows exactly how many child class it has
    b
    m
    a
    • 4
    • 8
  • p

    poohbar

    01/23/2018, 2:00 PM
    Is there a solid step by step guide on how to solve this build error?
    Runtime JAR files in the classpath should have the same version.
    For the life of me I can't find what's pulling in the wrong version of stdlib.
    e
    d
    i
    • 4
    • 12
  • m

    marcinmoskala

    01/23/2018, 4:05 PM
    Looks like there is something wrong with https://try.kotlinlang.org/ It is loading definitively on my machine and it displays a lot of errors
    r
    • 2
    • 3
Powered by Linen
Title
m

marcinmoskala

01/23/2018, 4:05 PM
Looks like there is something wrong with https://try.kotlinlang.org/ It is loading definitively on my machine and it displays a lot of errors
r

Ruckus

01/23/2018, 4:15 PM
Works fine here
m

marcinmoskala

01/23/2018, 4:19 PM
Maybe something with Indonesia
r

Ruckus

01/23/2018, 4:20 PM
Could be a rogue ad-blocker rule too. It's hard to tell without more data points.
View count: 2