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

    corneil

    09/12/2019, 11:57 AM
    You are always going to need the Kotlin stdlib because the compiler will generate call to stdlib just like Java compiler generates calls to java.lang for some cases.
    t
    j
    9 replies · 3 participants
  • a

    Akhil Suseelan

    09/12/2019, 2:15 PM
    How to convert
    MutableMap<String, Dequeue<String>>
    to
    MutableMap<String, Array<String>>
    t
    2 replies · 2 participants
  • f

    Florian

    09/13/2019, 7:45 AM
    Single expression syntax is discouraged on
    Unit
    functions, right?
    l
    s
    +1
    26 replies · 4 participants
  • j

    Johan Alkstål

    09/14/2019, 5:07 PM
    I've never seen anything like this before so it looks very odd.
    n
    k
    +2
    4 replies · 5 participants
  • f

    Florian

    09/15/2019, 9:22 AM
    Default arguments and named parameters aside, does Kotlin follow the exact same rules regarding function overloading as Java?
    s
    2 replies · 2 participants
  • t

    tipsy

    09/15/2019, 6:22 PM
    is there any way to get rid of the auto-generated
    INSTANCE
    on objects (the one that's visible from java)?
    r
    2 replies · 2 participants
  • t

    theopaintsil

    09/15/2019, 6:32 PM
    any idea on how i can connect springboot to sqlite datasource?
    :stackoverflow: 6
    r
    6 replies · 2 participants
  • s

    Soren Valle

    09/15/2019, 6:48 PM
    How does one check to see if a property value that is declared as type Any has been initialized with a function? i.e.
    class SomeClass {
        var someProp: Any? = null
    }
    
    fun main() {
       val someClass = SomeClass()
        someClass.someProp = {
            println("I do things")
        }
    
        // else where
    
        if(someClass.someProp is Function<*>){
            someClass.someProp() // invoke not found...
        }
    }
    a
    m
    5 replies · 3 participants
  • j

    Jacob Richards

    09/15/2019, 9:08 PM
    I’ve started with Kotlin a couple of days ago and I’m pretty overwhelmed, because I don’t know ANY Java. I’ll be using Kotlin at my new job. Should I start with Java? If so, what’s the best resource for getting started with Java?
    d
    a
    +1
    26 replies · 4 participants
  • g

    Greg Stepniewski

    09/16/2019, 11:34 AM
    Trying to understand why is this
    suspend fun loadTwoThings() = coroutineScope {
       val job1 = async { getDataOne() }
       val job2 = async { getDataTwo() }
       saveData(job1.await(), job2.await())
    }
    different from this
    suspend fun loadTwoThings() = {
       val job1 = async { getDataOne() }
       val job2 = async { getDataTwo() }
       saveData(job1.await(), job2.await())
    }
    As I understand, if I cancel a coroutine that called
    loadTwoThings
    , without coroutineScope the two async will keep running. Also, if one async fails it will let the other keep running. Why is that? A failed child is supposed to cancel its parent, and a cancelled parent is supposed to cancel its children. Are the two asyncs not children of the main coroutine? What exactly does
    coroutineScope
    do that makes a difference?
    d
    19 replies · 2 participants
  • b

    bitkid

    09/16/2019, 11:39 AM
    how can i convert
    listOf(Pair("a","b"), Pair("a","c"), Pair("b","d"))
    to
    mapOf("a" to ["b","c"], "b" to "d")
    ?
    d
    2 replies · 2 participants
  • m

    martin

    09/16/2019, 4:44 PM
    hi everyone! pretty noob question here, I come from a Go background and I'm looking for something like composition in Kotlin, I know there's inheritance in the way that I can define a class like
    class Person(val name: String, val lastName: String)
    class Employee(val name: String, val lastName: String): Person(name, lastName)
    but is there a way to have that Employee class just inherit all the properties of Customer, without listing them all explicitly as properties ? my guess is no, but I may be missing something
    j
    j
    5 replies · 3 participants
  • r

    Ran Magen

    09/16/2019, 4:56 PM
    you mean by using a
    (T) -> (R?)
    and then
    mapNotNull
    ? That'd work (assuming
    T : Any
    ) but it would create an intermediate list, which ideally I'd like to avoid.
    e
    a
    +1
    3 replies · 4 participants
  • s

    spicyspiders

    09/17/2019, 2:19 AM
    Hi everyone! - when we are using Kotlin data class with javax.persistence entity, does it make sense to have something like
    @Column(nullable = false)
        val locationId: String?,
    - if the db schema defines not null, does it make sense to mark the data class field as nullable? What is the behaviour in such a case?
    a
    k
    4 replies · 3 participants
  • v

    vineethraj49

    09/17/2019, 5:16 AM
    does
    withTimeoutOrNull
    not work with
    readBytes
    ? example, this always works (and I’m pretty sure 1ms will timeout since its a remote URL)
    val bytes = withContext(<http://Dispatchers.IO|Dispatchers.IO>) {
                            withTimeoutOrNull(1) {
                                URL(urlPath).readBytes()
                            }
                        }
    d
    1 reply · 2 participants
  • e

    Esa

    09/17/2019, 12:55 PM
    Hi, I have a spring boot project in which I’ve a Service (just a
    class xyzService.kt
    ). In this service, i have several private values. Now, for the usecase I’m trying to solve in this service, I wanted to have an
    abstract inner class Action
    which has 1 more layer of inner classes, like
    inner class Action.Cancel
    ,
    Action.Start
    etc (actual usecases are a bit more complex but I guess this translates okay). Each of these inner classes should also have access to the values in the top level service class. Then from the service class (but outside the Action class) I wish to be able to do
    Action.Cancel().execute()
    (execute is an overridden function from the superclass). However, I seem to run into some issues with these visibility modifiers. When attempting to interact with the values in the top level service class, I get the following:
    Constructor of inner class Start can be called only with receiver of containing class
    . Am I using the wrong hierarchy here? What’d be more appropriate? Does this seem like a wrong way to do things?
    t
    m
    5 replies · 3 participants
  • f

    Florian

    09/18/2019, 9:11 PM
    underscores for default parameters does currently not work? I thought I read that somewhere
    t
    c
    +1
    9 replies · 4 participants
  • s

    spicyspiders

    09/19/2019, 2:27 AM
    In a DTO data class containing
    people: List<Person>?
    is it safer to do
    people: List<Person?>?
    instead? i.e. people field can be null and also list containing null or empty?
    a
    t
    +1
    6 replies · 4 participants
  • f

    Florian

    09/19/2019, 7:54 AM
    Does this argument really hold when the IDE already has these little parameter hints?
    k
    v
    +5
    33 replies · 8 participants
  • f

    Florian

    09/19/2019, 9:47 PM
    "On the JVM: the named argument syntax cannot be used when calling Java functions because Java bytecode does not always preserve names of function parameters." This sentence just means that I can't call Java methods from Kotlin with the named parameter syntax?
    :yes: 4
    r
    d
    6 replies · 3 participants
  • j

    Johan Alkstål

    09/20/2019, 5:32 AM
    How would you import a Kotlin project into another project?
    t
    e
    2 replies · 3 participants
  • j

    James Richardson

    09/20/2019, 5:21 PM
    Is anybody using bazel to compile kotlin in a real world production environment. I have tried a couple of times. It seems to basically not work, except for toy demos. Am I missing something? It would be great to hear of real life projects. Do you have to maintain your own rulesets?
    c
    t
    8 replies · 3 participants
  • m

    Matthew Holmes

    09/21/2019, 4:53 PM
    Hi, I'm new to kotlin but have experience with python/django. I'm embarrassed to say I'm immediately having issues just with the very beginning of the basic tutorial from kotlin's website: https://play.kotlinlang.org/hands-on/Building%20Web%20Applications%20with%20React%20and%20Kotlin%20JS/02_Setting_up. I tried running yarn start and got what's in the code snippet. Has anyone seen this before?
    Untitled
    k
    4 replies · 2 participants
  • f

    Florian

    09/21/2019, 7:02 PM
    what is the reason that default parameter values don't support type inference?
    k
    2 replies · 2 participants
  • s

    Slackbot

    09/23/2019, 11:48 AM
    This message was deleted.
    t
    c
    +2
    8 replies · 5 participants
  • f

    Florian

    09/23/2019, 5:06 PM
    I can't overload a
    vararg
    function with an
    Array
    of the same type because the vararg is internally represented as an array on the JVM? (I know I can use the spread operator)
    k
    8 replies · 2 participants
  • s

    spicyspiders

    09/24/2019, 12:26 AM
    The kotlin in action book has a section where it recommends to make data classes immutable using val. It states that kotlin creates the toString, equals and hashCode methods that we used to implement on our own in Java and gives this as a reason why immutable data classes are recommended. I'm having a hard time understanding why it is recommended this way. What are your thoughts on this?
    j
    a
    +2
    6 replies · 5 participants
  • u

    ursus

    09/24/2019, 4:41 AM
    should top level vals be ALL_CAPS_CASE?
    n
    c
    +2
    8 replies · 5 participants
  • f

    Florian

    09/24/2019, 8:00 PM
    In Java it is said that varargs are just syntactic sugar for arrays. Is this also true for Kotlin or can it do anything arays can't?
    j
    c
    +2
    9 replies · 5 participants
  • f

    Florian

    09/25/2019, 8:34 AM
    I'm trying to figure out why multiple
    vararg
    parameters are not allowed even if they have different types
    l
    r
    13 replies · 3 participants
Powered by Linen
Title
f

Florian

09/25/2019, 8:34 AM
I'm trying to figure out why multiple
vararg
parameters are not allowed even if they have different types
l

Luca Nicoletti

09/25/2019, 8:46 AM
vararg
must be the last parameter, so, having 2 of them is not possible as only the latter would really be the last one
f

Florian

09/25/2019, 9:19 AM
well you can have a parameter after it if you use the named argument syntax
l

Luca Nicoletti

09/25/2019, 9:19 AM
Only when calling the function
But you can’t declare a function having 2 varargs
f

Florian

09/25/2019, 1:49 PM
right, but I am wondering why that is
Maybe I am missing something
I understand why its necessary when both varargs have the same type or one is a supertype
but I could pass
1, 2, 3, "bla", "blubb"
to a function with an
Int
and a
String
vararg
r

Ruckus

09/25/2019, 3:27 PM
Because "different types" doesn't mean much. For example:
interface A
interface B
class AI : A
class BI : B
class AB : A, B
fun x(vararg a: A, vararg b: B) { ... }
x(AI(), AB(), BI())
Where is the division line? That's a simple example. It can get far more complicated, and that's even without taking things like generics into account.
f

Florian

09/25/2019, 9:24 PM
sure but couldn't it still be supported for types where it doesn't lead to ambiguity?
just a theoretical question
r

Ruckus

09/25/2019, 10:46 PM
Not in a way that wouldn't lead to all sorts of confusion and edge cases.
f

Florian

09/26/2019, 6:50 AM
I see, thanks
View count: 1