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

    Hullaballoonatic

    09/11/2018, 11:46 PM
    sure would be nice to have
    ^
    as a power operator
    s
    e
    • 3
    • 21
  • v

    ValV

    09/13/2018, 2:13 AM
    How to properly implement
    addListener { ... }
    ? Java's example shows something like
    addListener((obs, oldVal, newVal) -> { ... })
    s
    r
    a
    • 4
    • 50
  • s

    Sam

    09/13/2018, 2:29 PM
    Question on covariance. Container is covariant on T but for this case i ignored out modifier on T and as expected processContainer1 fails at compile time ( required<Number> but found <Int>). Just wondering about processContainer which ensures type safety as well. Is there any reason why "out" would be preferred over T : Number?
    class Container< T : Number > (private var value : T ) {
        fun getContainedValue() : T = value
    }
    
    fun <T : Number > processContainer( container : Container<T> ) {
        container.getContainedValue()
    }
    
    fun processContainer1( container : Container<Number> ) {
        container.getContainedValue()
    }
    
    fun main(args: Array<String>) {
    
        val intContainer = Container(2)
    
        processContainer( intContainer )
        processContainer1( intContainer )  // Errors
    }
    m
    d
    • 3
    • 9
  • u

    ursus

    09/13/2018, 2:55 PM
    Ive got a stupid question. In Room entity (data class) has a primary key id property which is autogenerate. So when inserting I dont want to add the id. If I put a default value on it, kotlin will make me label all the params since it is first. Whats the standard way of takling this, factory method?
    d
    • 2
    • 1
  • j

    jdn

    09/13/2018, 6:01 PM
    I'm using Room on Android and I've replaced AsyncTask with coroutines. It seems to work but I'm wondering if there is a better way than
    GlobalScope.launch { dao.insert(note) }
    for simple background work where I don't expect a result. Also, would
    thread { dao.insert(note) }
    be an appropriate alternative?
    e
    • 2
    • 2
  • h

    Hullaballoonatic

    09/13/2018, 6:03 PM
    what is
    with
    and how do I make use of it?
    s
    s
    +3
    • 6
    • 36
  • s

    supotuco

    09/13/2018, 11:07 PM
    maybe rename
    private Foo foo;
    to
    private Foo mFoo;
    s
    • 2
    • 2
  • v

    ValV

    09/13/2018, 11:42 PM
    What DSL stands for?
    s
    s
    • 3
    • 11
  • d

    Daniele Segato

    09/14/2018, 4:18 PM
    Exactly when I tough i was getting pro at kotlin I fall on the most basic thing... this code below do not compile 🙂 I know about ranges... I can do
    in Int.MIN_VALUE until 0
    I also know I can save the value and compare to 0 using a
    when
    with no parameter. But are these really the only ways? Can't I do something similar to the code below? And to check !0 with ranges I would have to write:
    !in in 1..Int.MAX_VALUE && !in -1 downTo Int.MIN_VALUE
    But this doesn't look right, there must be another way, right?
    open_integer_conditions_in_when.m
    a
    s
    a
    • 4
    • 19
  • h

    Hullaballoonatic

    09/15/2018, 5:25 PM
    e.g.
    class BasePerson : Person
    Interface Person
    ?
    p
    • 2
    • 1
  • v

    ValV

    09/15/2018, 6:01 PM
    Is it possible to iterate over statements in a block? E.g.
    {
      someFun()
      "Some Text"
      anything + else
    }
    In order to "catch" some specific statements
    d
    k
    n
    • 4
    • 9
  • o

    otakusenpai

    09/16/2018, 1:25 PM
    hello I hav a MutableList of Ints, where each Int is like this: 24 24 25 26 25 26 24 I want this to be coverted to a map with Key being either 24 or 25 and value being the number of 24s. Like this: 24 3 25 2 26 2 Is there an easy function in the library to do that?
    n
    a
    i
    • 4
    • 43
  • v

    Vladyslav Sitalo

    09/16/2018, 2:02 PM
    I have an java interop question: I have a Kotlin function that accepts vararg argument (i.e.
    fun processStrings(vararg strings: String)...
    When I try to call it from Java though it’s seen as a function that accepts an array of strings instead of vararg function. Is there a way to make this function accept vararg from Java’s perspective?
    n
    • 2
    • 4
  • o

    otakusenpai

    09/16/2018, 8:48 PM
    hey guys So i hav a base class called Wearable and this class has a member named "name" And i hav another class name ClothTunic and this class inherits the class Wearable plus has a member named "armor" And say for examples sake, a class named PowerRing which inherits the Wearable and has a member named "strenght" So all this wearables are managed by a WearableManager which has a function called getTotalArmor() : Int which returns the total armor from all these wearables tht a entity has. So my question was this: How do i know which Wearable has a "armor" variable or a "strength" variable? How do i do it in Kotlin?
    s
    n
    • 3
    • 20
  • o

    otakusenpai

    09/16/2018, 10:46 PM
    Ok So I hav a class name StrawHat, like this
    class StrawHat {
        constructor() : Wearable(name = "Straw Hat") {
    
        }
    }
    The constructor of this class gives an error: Expecting a this or super constructor call.... How do i call this type of constructors?
    s
    • 2
    • 2
  • v

    v79

    09/17/2018, 8:38 AM
    There doesn't seem to be a LinkedList in the Kotlin std library - any obvious alternatives?
    s
    m
    +2
    • 5
    • 9
  • c

    Chris

    09/17/2018, 9:35 AM
    hiya, is there any way to quickly get number of decimal digits from
    Double
    ? I would like the exact number of deciaml digits, ie. 424.234 would return 3 or “234” (either would be good) thanks in advance.
    r
    k
    • 3
    • 4
  • k

    karelpeeters

    09/17/2018, 10:09 AM
    And
    0b_1100_0000
    should just work like that.
    k
    • 2
    • 3
  • s

    Slackbot

    09/17/2018, 11:27 AM
    This message was deleted.
    d
    d
    • 3
    • 2
  • s

    SomeCat

    09/17/2018, 12:44 PM
    Does Kotlin have some sort of built-in mechanism to update text files? My task is to read a text file, and parse them line by line. When I match a specific pattern, I want to write a slightly changed line, otherwise the original line. I could implement such a processor myself, but I am wondering if there is already support for that in Kotlin?
    d
    v
    • 3
    • 5
  • s

    Sudhir Singh Khanger

    09/17/2018, 2:20 PM
    fun isFavorite(otherIceCream: IceCream) = iceCream == otherIceCream
    What is going on in this syntax? We have one equality operator and another is assignment.
    f
    d
    • 3
    • 4
  • s

    Sam

    09/17/2018, 3:40 PM
    How to read this? val filter = {predicate: (Int) -> Boolean -> {collection: List<Int> -> collection.filter(predicate) }}
    d
    r
    • 3
    • 10
  • s

    subashz

    09/17/2018, 4:29 PM
    Any way to find this: https://stackoverflow.com/questions/52353007/find-kotlin-classes-implementing-an-interface
    a
    • 2
    • 2
  • s

    subashz

    09/17/2018, 4:30 PM
    Is this possible in Kotlin ?
    e
    l
    • 3
    • 3
  • h

    Hullaballoonatic

    09/17/2018, 6:29 PM
    guess i can just use enums or sealed classes instead
    s
    a
    • 3
    • 12
  • h

    Hullaballoonatic

    09/18/2018, 12:14 AM
    i can't be the only one that thinks the constant casting between ints, doubles, etc in arithmetic kinda ruins the beautiful readability of kotlin
    h
    • 2
    • 5
  • s

    Slackbot

    09/18/2018, 11:08 AM
    This message was deleted.
    a
    j
    k
    • 4
    • 3
  • c

    CamilleBC

    09/19/2018, 1:31 PM
    Hello ! I am trying to understand how to get Contacts (from ContactsContract) using a ViewModel. I only found the official tutorial which uses a CursorLoader (https://developer.android.com/training/contacts-provider/retrieve-names). Are there any tutorials, guides or articles who could help understand how to do that? Thank you for your patience! EDIT: Ignore the question as it wasn't related to Kotlin. EDIT2: If you care, it seems that I was understanding it the wrong way. ContactsContract is a ContentProvider, which is an API on a database. It would be redundant with a Room/DAO implementation.
    a
    k
    j
    • 4
    • 7
  • o

    otakusenpai

    09/19/2018, 7:27 PM
    So I hav a object called BasicSword which is a derived class of MeleeWeapon, and in a object called BasicSoldier i hav some code like this:
    object BasicSoldier {
       fun init() {
          this.meleeWeapon = BasicSword
          .....
        }
        lateinit var meleeWeapon : MeleeWeapon
    How do i instantiiate the BasicSword object ? It has a fun init() method which is used to instantiate it. Pls help
    a
    s
    r
    • 4
    • 13
  • g

    Guschinaglia

    09/20/2018, 11:58 AM
    Hi guys! i'm creating a new project using Kotlin + Spring and Gradle but for some reason i receive this error:
    -.kt
    m
    d
    • 3
    • 5
Powered by Linen
Title
g

Guschinaglia

09/20/2018, 11:58 AM
Hi guys! i'm creating a new project using Kotlin + Spring and Gradle but for some reason i receive this error:
-.kt
m

morys

09/20/2018, 12:00 PM
You probably need to add 'Kt' to your gradle springBoot mainClassName configuration
➕ 2
springBoot { mainClassName = 'com.gustavo.VehicleServices.VehicleServicesApplicationKt' }
➕ 2
g

Guschinaglia

09/20/2018, 12:03 PM
Hi! Worked well.. There is a reason for it ? My class does not have this name. Its just because of the extension ?
d

diesieben07

09/20/2018, 12:07 PM
https://kotlinlang.org/docs/reference/java-to-kotlin-interop.html#package-level-functions
➕ 3
g

Guschinaglia

09/20/2018, 12:36 PM
Got it ! Many thanks !
View count: 1