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

    muralimohan962

    09/30/2018, 5:02 PM
    Any advantages over other? Please suggest.
    k
    b
    +2
    • 5
    • 6
  • p

    poohbar

    10/01/2018, 3:49 PM
    which of
    also
    ,
    run
    ,
    let
    ,
    apply
    etc should I use: 1. the extension must be lambda that takes one parameter (like let), can't be
    this
    2. it automatically returns the input just like
    apply
    does
    l
    a
    +2
    • 5
    • 7
  • n

    Nikita Khlebushkin

    10/02/2018, 9:34 AM
    What is the advantage of using
    asSequence
    before `filter`s and `map`s?
    k
    u
    +3
    • 6
    • 9
  • c

    CamilleBC

    10/03/2018, 8:59 AM
    To stay on the same topice (almost 😛 ), I have a question about data types. For each item, I have a KEY, a PATH and a NAME value. I would like to be able to find the two others quickly if I have any of the three. Is there a kotlin way to do it efficiently? I was thinking of doing a hashmap with a data class that contains the two other value, but then it only works if I searrch by KEY, not by PATH or NAME. Any idea?
    h
    a
    k
    • 4
    • 26
  • h

    hudsonb

    10/03/2018, 5:10 PM
    So then you mean
    internal
    ?
    k
    • 2
    • 1
  • v

    ValV

    10/04/2018, 12:54 AM
    I have a question that I wanted to ask long ago. Why online Kotlin docs do not display code snippets instantly? One just has to wait few minutes for it to appear
    h
    m
    • 3
    • 8
  • f

    forcelain

    10/04/2018, 8:03 AM
    private val items : MutableList<String> by lazy {
            // a lot of init code
        }
    how do I exclude my initialisation code into a separate function? I can think of creating something like
    private val items : MutableList<String> by lazy {
            init()
    }
    fun init() : MutableList<String> {...}
    but maybe there is more elegant way
    d
    • 2
    • 8
  • s

    Sam

    10/04/2018, 6:37 PM
    Which one makes more sense? I don't care about the return values here
    mFilter.run {
                addAction( Intent.ACTION_PACKAGE_INSTALL )
                addAction( Intent.ACTION_PACKAGE_ADDED )
                addAction( Intent.ACTION_PACKAGE_REMOVED )
                addAction( Intent.ACTION_PACKAGE_FULLY_REMOVED )
                addDataScheme("package")
            }
    
            mFilter.apply {
                addAction( Intent.ACTION_PACKAGE_INSTALL )
                addAction( Intent.ACTION_PACKAGE_ADDED )
                addAction( Intent.ACTION_PACKAGE_REMOVED )
                addAction( Intent.ACTION_PACKAGE_FULLY_REMOVED )
                addDataScheme("package")
            }
    h
    • 2
    • 2
  • s

    Sam

    10/04/2018, 7:15 PM
    Is there a better way to write this?
    val launchUri = try {
                    if( isAvailable() ) {
                        Uri.parse( "..." )
                    } else {
                        Uri.parse("..." )
                    }
                } catch ( e : android.content.ActivityNotFoundException ) {
                    if( isAvailable() ) {
                        Uri.parse( "..." )
                    } else {
                        Uri.parse("..." )
                    }
                }
    t
    v
    +2
    • 5
    • 10
  • n

    Nikky

    10/04/2018, 8:36 PM
    in combi with ktlint, which can automatically configure the formatting options in idea to conform to (afaik) the kotlin style guidelines
    m
    • 2
    • 2
  • m

    Mike

    10/04/2018, 9:10 PM
    @ValV IntelliJ can also provide hints that formatting doesn’t conform. In inspections, search for
    formatted according to project settings
    and turn it on. Appears under Kotlin. Then if code doesn’t conform to formatting, it will have the colour you chose here with squiggly lines around it. I’m not sure if this will appear in an Analyze run. You may be able to modify the Analyze rules and have IntelliJ expose formatting issues.
    v
    • 2
    • 4
  • v

    ValV

    10/06/2018, 10:39 AM
    I have an object created from Java class
    IntegerStringConverter
    that trows exceptions like
    java.lang.NumberFormatException
    , is it possible to catch or suppress them without
    try ... catch
    block?
    k
    • 2
    • 7
  • s

    Sam

    10/06/2018, 3:16 PM
    Shouldn't this fail at compilation? or does return default to false?
    val list = listOf( 1, 2, 3, 4, 5 )
        val evenList = list.filter {
            return
            it % 2 == 0
        }
    v
    • 2
    • 35
  • v

    ValV

    10/07/2018, 8:03 AM
    Confusing not-so-different syntaxes
    o
    • 2
    • 4
  • v

    ValV

    10/07/2018, 10:30 AM
    How can I do generic cast? I need something like:
    inline fun <reified T> convert(text: String): Any? {
      return try {
        text to T // something bad is happening here
      } catch (e: Exception) {
        null
      }
    }
    s
    g
    • 3
    • 4
  • r

    Rohit Surwase

    10/08/2018, 1:08 AM
    Hi, I am new to kotlin and just started using Coroutines. I have few doubts. 1. If Coroutines is a language feature then why do we need to add dependencies. 2. How can I try latest 1.3 RC version in Android Studio. I tried following (and of course at its right place)
    // Downloaded 1.3. early preview plugin of Kotlin for Android Studio
    
    ext.kotlin_version = '1.3.0-rc-46'
    // ext.kotlin_version = '1.3.0-rc-57'
    maven { url '<https://dl.bintray.com/kotlin/kotlin-eap>' }
    classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    
    implementation ("org.jetbrains.kotlinx:kotlinx-coroutines-core:0.30.1") {
            exclude group: "org.jetbrains.kotlinx", module: "atomicfu-common"
        }
        implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:0.30.1'
    Above setup giving me error
    No route to host (connect failed)
    3. What working for me is just
    ext.kotlin_version = '1.2.71'
    
    implementation ("org.jetbrains.kotlinx:kotlinx-coroutines-core:0.30.1") {
            exclude group: "org.jetbrains.kotlinx", module: "atomicfu-common"
        }
        implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:0.30.1'
    Please guide me in the right direction. Thanks.
    r
    • 2
    • 3
  • h

    Hullaballoonatic

    10/08/2018, 3:42 AM
    quick question.... do any of you get tired of answering the same questions over and over? what are those questions?
    s
    v
    k
    • 4
    • 5
  • k

    karelpeeters

    10/08/2018, 9:04 AM
    Of course the constructors of classes should be able to access
    this
    , and default parameters are evaluated in a constructor.
    p
    e
    • 3
    • 6
  • m

    miha-x64

    10/08/2018, 7:09 PM
    Attempting to use Kotlin PSI (writing a Detekt rule). Trying to find annotation on a function.
    function.annotationEntries.any { it.shortName?.identifier == "PublishedApi" }
    works but may be false-positive for
    some.custom.package.PublishedApi
    . How should I fix this, where's annotation FQN?
    k
    • 2
    • 2
  • m

    miha-x64

    10/08/2018, 7:41 PM
    One more thing: how can I check whether lambda expression will be inlined? I can ascent until I meet ValueArgument/ValueArgumentList/CallExpression, but can't find a way to get method being called.
    k
    • 2
    • 1
  • m

    marcelo

    10/08/2018, 10:50 PM
    need to do the following:
    val counterWithTwoTags = metric.counterTwoTags("my.counter.name", "key1", "key2")
    try{
      someHttpCall()
      counterWithTwoTags("value1", "value2")
    catch(Exception e) {
      counterWithTwoTags("errorValue1", "errorValue2")
    }
    I want to make sure that the
    name
    for the counter remains immutable, but the the value is not. I was thinking that companion objects was the right way, but this seems more like for static methods.
    j
    • 2
    • 3
  • m

    marcelo

    10/09/2018, 2:42 AM
    so if I have something like this:
    data class MetricTag<T>(val name: String, var value: T)
    s
    • 2
    • 1
  • m

    marcelo

    10/09/2018, 2:42 AM
    I can mutate the value??
    n
    • 2
    • 5
  • v

    ValV

    10/09/2018, 9:20 AM
    How can I marshal
    ObservableList<ObservableList<ObservableValue<Any>>>
    ? Do I need inherit and annotate it? Are there better (Kotlin-specific) ways to marshal an object?
    h
    n
    • 3
    • 4
  • m

    Matheus

    10/09/2018, 3:29 PM
    Yeah, it would make my life easier, but I need all the references to print this on a chart (dates on x-axis, values on y-axis) 😁
    a
    a
    • 3
    • 7
  • p

    poohbar

    10/10/2018, 4:00 PM
    yes
    a
    • 2
    • 1
  • d

    diesieben07

    10/10/2018, 4:01 PM
    Use
    buildSequence
    p
    a
    +2
    • 5
    • 13
  • s

    serebit

    10/10/2018, 6:06 PM
    any particular reason you need XML over JSON?
    v
    • 2
    • 1
  • f

    fkrauthan

    10/10/2018, 6:14 PM
    Is there any way to use
    kotlinx.serialization
    for a Javascript project to convert my data class to a simple Javascript object and back without all the heavy auto gen code and to string serialization?
    k
    • 2
    • 3
  • v

    ValV

    10/11/2018, 11:38 AM
    Why there are many projects in various VCSs that contain
    .idea
    folder? Isn't it IDE configs that should not be put into version control?
    a
    • 2
    • 8
Powered by Linen
Title
v

ValV

10/11/2018, 11:38 AM
Why there are many projects in various VCSs that contain
.idea
folder? Isn't it IDE configs that should not be put into version control?
a

arekolek

10/11/2018, 11:45 AM
Some files are project-specific See https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
I usually start out with https://www.gitignore.io/api/androidstudio
v

ValV

10/11/2018, 11:49 AM
I've added
.idea
to
.gitignore
, but left
.iml
file
That should work even if all IDE-specific files are excluded, right?
a

arekolek

10/11/2018, 11:53 AM
I’m not sure what you mean by “but left
.iml
file”, also I can’t know what files were already checked in before modifying the
.gitignore
One way to check if your setup works would be to clone the repository to a new directory and try to open it. Simulate a new person joining the project
v

ValV

10/11/2018, 11:55 AM
Gotta try it...
It works. One do not need any IDEA config files in repository with properly configured build system. IDEA imports its configs from the build system (at least for me it works with Maven)
View count: 4