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

    Narayan Iyer

    11/03/2018, 2:39 PM
    This snippet of code is from the
    Coursera
    . I tried it on the Kotlin
    REPL
    . Any ideas why it is giving that error? Thanks! BTW, I get the same error for:
    displayError()
    !!!
    m
    • 2
    • 2
  • l

    Luke

    11/04/2018, 8:32 PM
    I'm trying to setup my environment to contribute to Kotlin by following Yoshinori Isogai's talk of last KotlinConf, but I'm hitting a wall when running the command
    ant -f update_dependencies.xml
    . I get an error saying:
    Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=512m; support was removed in 8.0
    Buildfile: update_dependencies.xml does not exist!
    Build failed
    Any tips?
    v
    i
    • 3
    • 4
  • f

    febs

    11/05/2018, 9:39 AM
    Everybody, I got a question about lambda and SAM conversion. The subject is Android here, but my question is actually Kotlin related so I post here. Why if I do use the "lambda version" to override the single interface method ( top in the image) I don't have to declare the "object: " explicitly, while if I try to explicitly override the single method, I have to? Thanks 😄
    s
    k
    • 3
    • 6
  • j

    jacob

    11/05/2018, 10:51 AM
    listOf() is by default immutable. mutableListOf() is mutable.
    a
    d
    • 3
    • 3
  • k

    karelpeeters

    11/05/2018, 11:30 AM
    Although the last commit there is a year ago.
    o
    • 2
    • 1
  • a

    APXEOLOG

    11/05/2018, 1:22 PM
    Guys how do i change function to make it get
    T
    from the
    klass
    ?
    fun <T> getProperty(klass: KClass<*>): T? {
            return properties.find { it::class == klass } as T?
        }
    Right now it's working as
    entity.getProperty<String>(String::class)
    and i want
    entity.getProperty(String::class)
    n
    d
    s
    • 4
    • 11
  • k

    kartikpatodi

    11/05/2018, 7:12 PM
    can anyone please explain the following behavior
    class A1(private val x: Int) {
        private val y: Int = 0
    }
    generates this code in Java
    public final class A1 {
        private final int y;
        private final int x;
    
        public A1(int x) {
            this.x = x;
        }
    }
    while
    class A2(private val x: Int) {
        private val y: Int
        init {
            y = 0
        }
    }
    generates
    public final class A2 {
        private final int y;
        private final int x;
    
        public A2(int x) {
            this.x = x;
            this.y = 0;
        }
    }
    Why if init block
    y=0
    is in constructor of
    A2
    and not otherwise in case of
    A1
    ?
    m
    m
    k
    • 4
    • 8
  • y

    yen

    11/06/2018, 9:39 AM
    I’ve recently checked out Kotlin Exposed, looks really cool, but feels rather immature at this point. What’s everyone’s favourite database library?
    s
    r
    +4
    • 7
    • 13
  • n

    Nikky

    11/06/2018, 8:13 PM
    if the if missing a closing
    )
    ?
    a
    • 2
    • 2
  • k

    karelpeeters

    11/06/2018, 8:14 PM
    Otherwise still doesn't compile because it's missing a real return.
    a
    • 2
    • 1
  • n

    Nikky

    11/06/2018, 8:16 PM
    actually
    a ?: let {} ?: return b
    seems okay a is final and always initialized to null so the let block is dead code
    a
    k
    s
    • 4
    • 5
  • a

    Alpesh Vas

    11/06/2018, 8:33 PM
    Still waiting for correct answer.
    k
    k
    n
    • 4
    • 11
  • n

    Nikky

    11/06/2018, 8:38 PM
    if a was not val/final then it could fall though and return
    c
    a
    s
    • 3
    • 5
  • k

    Kevin Huang

    11/07/2018, 10:35 AM
    interesting overload
    s
    m
    • 3
    • 4
  • k

    Kevin Huang

    11/07/2018, 10:44 AM
    Which features attract you to use Kotlin?
    s
    k
    +5
    • 8
    • 20
  • r

    rnpy

    11/08/2018, 9:59 AM
    functionThatTakesAVarargAsParameter(*fictionData )
    ?
    c
    • 2
    • 2
  • a

    APXEOLOG

    11/08/2018, 11:56 AM
    Oh, the
    arrayOf
    exactly what i need, thanks
    p
    • 2
    • 1
  • c

    CamilleBC

    11/08/2018, 12:18 PM
    Is it possible to create a generic function extension? I've tried this but it doesn't work:
    fun List<E>.getDifference(other: List<E>) = this.union(other) - this.intersect(other)
    s
    s
    • 3
    • 3
  • n

    nestserau

    11/08/2018, 4:47 PM
    Guys, the IDE asks me to convert the comparison of `UByte`s into a range check. And I would gladly do it, but if I do
    if (f.value in from..to && !c.isEmpty)
    , then it doesn’t compile saying
    Type interference failed
    . Any other options?
    fun notEmptyFieldInRange(from: UByte, to: UByte): Boolean {
            for ((f, c) in fields)
                if (f.value >= from && f.value <= to && !c.isEmpty)
                    return true
            return false
        }
    h
    n
    • 3
    • 9
  • s

    Serge

    11/08/2018, 9:51 PM
    If I have a package and have functions declared in it (not any class besides package itself) - is it possible by using reflection to obtain list of those declared functions? I have tried to do something like this -
    val o = object{}
    val mm = o.javaClass.declaredMethods
    but it doesn't return anything. is it possible at all? if so, would the function modifier affect this search (private, public, etc)?
    d
    • 2
    • 8
  • c

    ClaudiuB

    11/09/2018, 5:58 AM
    How should the
    Stateful by state()
    part of this should be interpreted?
    class MySuperCoolActivity : Activity(), Stateful by state()
    and
    state()
    is a global function
    k
    h
    • 3
    • 3
  • k

    kartikpatodi

    11/09/2018, 7:01 AM
    How to handle ui in a multiplatform project. I mean can ui be in the shared/common module?
    n
    • 2
    • 2
  • s

    Saiedmomen

    11/09/2018, 2:29 PM
    yeah that was what I was doing. But scratch files have a different ui and inline(only?) output console
    a
    • 2
    • 2
  • h

    himrin

    11/09/2018, 2:55 PM
    I can’t seem to get scratch files to run currently.
    a
    • 2
    • 4
  • l

    legzo

    11/09/2018, 4:01 PM
    Hi guys, I have a Kotlin module, packaged as a jar, that I use from a Java project I want to have a method that is visible from my Kotlin classes but not from the java project. From what I read on the doc (https://kotlinlang.org/docs/reference/visibility-modifiers.html) I thought that
    internal
    would do the trick but the internal function is visible from java, as : myInternalFunc$my_module_name. What am I missing ? 🤔 Mmmm read the doc a bit more and saw that internal is mapped to public in java with some name mangling. Do you know another way to do what I want to do ?
    y
    d
    k
    • 4
    • 3
  • f

    febs

    11/09/2018, 11:12 PM
    I am trying to debug some code. Some variables (newValue and tappedOperation here) are shown as a small circle with a "p" inside, and have several parameters (count, hash); while others (prevValue here) are shown with a different symbol. I feel like the latter shows the variable type (that's a double). But what about the others? They are arguments to a function call, but why are them so different here? THANKS ❤️
    m
    • 2
    • 1
  • s

    Stuart Rivero

    11/10/2018, 6:54 PM
    Hi, I'm trying to use the new gradle kotlin-dsl but my tests are not being run (although they are built). Is there an example project for this? The one generated with Intellij does not seem to run them. I'm using gradle 4.10.2, kotlin-dsl 1.3 and junit 5
    • 1
    • 1
  • b

    bodiam

    11/11/2018, 10:19 AM
    Maybe a stupid question, but I've got quite a few companion objects, which need to be accessed from Java. Is there somehow a way to make all the functions is the companion objects JvmStatic by default, or, at least, put an annotation on the companion object or something? It would save me a ton of annotations.
    👍 2
    e
    i
    • 3
    • 15
  • m

    MrNiamh

    11/11/2018, 7:33 PM
    Perhaps a silly question, how do people handle mocking data classes?
    n
    • 2
    • 2
  • c

    Chris Cunningham

    11/11/2018, 10:07 PM
    anyone got some good info about why kotlin went with its companion object concept over just having static?
    m
    • 2
    • 1
Powered by Linen
Title
c

Chris Cunningham

11/11/2018, 10:07 PM
anyone got some good info about why kotlin went with its companion object concept over just having static?
m

Mike

11/12/2018, 2:06 AM
static was java’s way of connecting something to the class rather than an instance of the class. IMO, it’s harder to manage and read as a static can appear anywhere in a class. It was also added to provide utility functions/builders etc on a class. With kotlin, forcing all methods of that type into one place makes it much easier to find all the class methods/properties as they can only be in one place. And with top-level functions and extension functions, I very rarely have any use for a companion object anyway. It seems like it’s mostly brought up by people new to the language that have not absorbed some of the other approaches and strengths of the language and therefore they want their ‘comfortable’ static. But as always, this is just one person’s opinion/interpretation/experience.
View count: 2