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
announcements
  • p

    Paul Woitaschek

    07/04/2019, 7:23 PM
    What's a possible use case for
    InvocationKind.AT_MOST_ONCE
    ? Use case as in: What is it good for, not how to use it.
    k
    • 2
    • 2
  • d

    Daniel

    07/04/2019, 9:38 PM
    Hi guys, I got a question in relation to a recent work problem: What might be the reason for not checking if the returned value of a function is not null when its defined as not null? To explain a bit: We have the input parameters checked with
    Intrinsics.checkParameterIsNotNull(..., "....");
    but not the returned value. The first question would be, how can this happen that a returned value is null even when its defined as not null? Unfortunately we got a data class for a backend response wrong: We set a property of the data class as non null, but it was nullable in the backend. So Gson was putting null in it. The said property was then propagated through different methods via
    return
    and way higher up something crashed. If there were a Intrinsic check in place in every method we would have had an easier time debugging the issue. There is most definitely a reason for why the kotlin team decided against it and I am curious for it! 🙂
    g
    a
    p
    • 4
    • 6
  • a

    Andrew Gazelka

    07/04/2019, 10:34 PM
    is it just me or would some code be sooooo much cleaner if there were extension interfaces
    s
    d
    • 3
    • 3
  • n

    Nir

    07/04/2019, 10:57 PM
    Unrelated question: is there a way to forward arguments generically to another function in kotlin?
    s
    k
    • 3
    • 14
  • k

    kschlesselmann

    07/05/2019, 8:10 AM
    Anyone an idea why IDEA complains about that? The code compiles fine
    k
    • 2
    • 6
  • t

    thana

    07/05/2019, 8:13 AM
    is there any way to declare a static (i know there is no static) extension property?
    k
    • 2
    • 4
  • m

    mike_shysh

    07/05/2019, 11:09 AM
    Hi, I wonder whether someone knows, what is the limit for String length in kotlin?
    d
    a
    • 3
    • 4
  • m

    mike_shysh

    07/05/2019, 11:11 AM
    I have 16k chars in String variable, and got an error when try to manipulate this string
    d
    • 2
    • 28
  • b

    bod

    07/05/2019, 12:13 PM
    Hello, World! I made an extension fun on a type that belongs to the Android sdk, and in a more recent version of this sdk they added a method to this type, with the same signature as my extension. To my surprise, in that case, the extension is ignored (the type's method wins). Thoughts?
    k
    r
    +2
    • 5
    • 19
  • m

    mc

    07/05/2019, 1:07 PM
    Is there a better way to accomplish the following (either through abstraction or existing stdlib functions)?
    fun <R> (suspend () -> R).fallbackTo(block: () -> R) : suspend () -> R = {
        try {
            this()
        } catch (e: Exception) {
            block()
        }
    }
    
    
    fun <T1, R> (suspend (T1) -> R).fallbackTo(block: (T1) -> R) : suspend (T1) -> R = { t1 ->
        try {
            this(t1)
        } catch (e: Exception) {
            block(t1)
        }
    }
    
    fun <T1, T2, R> (suspend (T1, T2) -> R).fallbackTo(block: (T1, T2) -> R) : suspend (T1, T2) -> R = { t1, t2 ->
        try {
            this(t1, t2)
        } catch (e: Exception) {
            block(t1, t2)
        }
    }
    d
    • 2
    • 2
  • i

    igor.wojda

    07/05/2019, 1:31 PM
    What is the best way to convert pascal case string into snake case string in Kotlin?
    "apiBaseUrl"  -> "api_base_url"
    p
    r
    +3
    • 6
    • 12
  • n

    Nir

    07/05/2019, 2:34 PM
    Is it possible to inherit from a data class?
    s
    g
    • 3
    • 45
  • a

    am414

    07/05/2019, 2:34 PM
    any help plz if I have many Constantsvalues in a class inside Companion object function and I don't wanna the imports be like this
    import com.john.movie.util.Constants.Companion.NOW_PLAYING_MOVIES
    import com.john.movie.util.Constants.Companion.POPULAR_MOVIES
    import com.john.movie.util.Constants.Companion.TOP_RATED_MOVIES
    import com.john.movie.util.Constants.Companion.UP_COMING_MOVIES
    this not working
    import com.john.movie.util.Constants.Companion.*
    k
    • 2
    • 9
  • d

    Dima Avdeev

    07/05/2019, 5:31 PM
    When will inline classes be released?
    l
    g
    • 3
    • 2
  • j

    JoshK

    07/05/2019, 7:27 PM
    What's the name for the left-hand notation in this example?
    val (first, second, third) = "first,second,third".split(",")
    ?
    j
    • 2
    • 2
  • w

    william

    07/05/2019, 9:04 PM
    im trying to match a json block with a regex (embedded in another document), and just the simple regular expression
    Regex("{}")
    shows up with the errors
    Dangling metacharacter
    on both the opening and closing bracket
    s
    k
    • 3
    • 11
  • n

    Nir

    07/05/2019, 11:46 PM
    https://youtrack.jetbrains.com/issue/KT-28552
    g
    • 2
    • 1
  • n

    Nir

    07/05/2019, 11:46 PM
    I apparently need to upgrade gradle to 5.0 but not obvious to me how to do that
    g
    • 2
    • 1
  • n

    Nir

    07/05/2019, 11:47 PM
    I feel like it's somewhat important that when you download IntelliJ and default create a Kotlin Native hello world, it should actually work....
    d
    m
    • 3
    • 5
  • t

    thiagoretondar

    07/06/2019, 1:47 AM
    what is the best approach when I want to compare only some fields (ignoring the values of some others) of two
    data class
    instances? One by one?
    g
    l
    i
    • 4
    • 4
  • i

    igor.wojda

    07/06/2019, 1:43 PM
    Assuming we have such method
    putData(property: KProperty1<out Any?, Any?>, value: Any?) { }
    Is there any way to check is
    property
    is of the same type as
    value
    ?
    d
    l
    d
    • 4
    • 7
  • h

    halirutan

    07/07/2019, 12:18 AM
    Is there something more recent?
    g
    • 2
    • 2
  • v

    ValV

    07/07/2019, 1:37 AM
    Guys, can you point some good examples, please, on how to implement (preferably in Kotlin) interactive command-line mode for an app, just like smbclient has?
    d
    n
    +2
    • 5
    • 56
  • n

    Nir

    07/07/2019, 3:38 PM
    Is there any way to call this with +:
    inline fun <T> T.add(f: T.() -> T) : T {
        return this.f()
    }
    r
    • 2
    • 5
  • n

    Nir

    07/07/2019, 4:06 PM
    So I was annoyed by having to choose between mutable dataclasses (which means they can mutate when passed as an input to a function), and immutable (all fields declared val), which means you have to mention the variable twice each time to do a replace operation. So came up with the following:
    interface MyInterface {
    }
    
    data class User(val x: String, val y: Int) : MyInterface
    
    inline operator fun <T : MyInterface> T.plus(f: T.() -> T) : T {
        return this.f()
    }
    
    fun main() {
        var n = User(x = "hello", y = 5)
        n += { copy(y = 7) }
    }
    c
    g
    +2
    • 5
    • 61
  • s

    SrSouza

    07/07/2019, 11:08 PM
    Hi guys, I want to know if this is a bug or anyone can explain this. The setValue is okay with this error, but why the getValue don't give me the same error?
    l
    • 2
    • 3
  • k

    Kulwinder Singh

    07/08/2019, 3:20 AM
    is there a any better way of doing this ? here i just want another list without first element
    -.kt
    r
    • 2
    • 7
  • m

    Mohamed Ibrahim

    07/08/2019, 9:16 AM
    is there anyway to use
    when
    with ignorecase when it comes to comparing strings
    d
    t
    d
    • 4
    • 6
  • f

    Florian

    07/08/2019, 10:00 AM
    Most operators can be called in their function form, like
    1.plus(2)
    . Is there also a form like this for
    in
    when it uses
    iterator
    (not
    contains
    )?
    d
    k
    +2
    • 5
    • 30
  • f

    Florian

    07/08/2019, 11:52 AM
    I am trying to figure out why we have IntRange and IntProgression
    d
    k
    • 3
    • 20
Powered by Linen
Title
f

Florian

07/08/2019, 11:52 AM
I am trying to figure out why we have IntRange and IntProgression
d

diesieben07

07/08/2019, 11:58 AM
IntProgression
can have a step, you could for example iterate from 0 to 10 in steps of 2 (0, 2, 4, 6, 8, 10).
IntRange
is an
IntProgression
where the step is always 1 and as such represents a closed range.
f

Florian

07/08/2019, 12:02 PM
so the word "Range" implies that no numbers are skipped?
ie no step
d

diesieben07

07/08/2019, 12:03 PM
Yes
The range [0, 10] includes all numbers 0 through 10.
That's why you can do
5 in 0..10
but not
5 in (0..10 step 2)
Actually you can do that. Huh.
Ah, but the range simply does a check where as the progression needs to loop through all the numbers to see if one matches
f

Florian

07/08/2019, 12:15 PM
makes sense
in a way, ranges are similar to arrays, right?
d

diesieben07

07/08/2019, 12:30 PM
No, a range is really just a start and end element
f

Florian

07/08/2019, 12:36 PM
ok
and what about progression
could you say that it is similar to an array
I mean I get that it generates the actual values in the iterators next function
but it can do a lot of the same things that an array with the same numbers could do
d

diesieben07

07/08/2019, 12:56 PM
That is true, yes. It's an Iterable.
k

karelpeeters

07/08/2019, 5:02 PM
Huh that's stupid, the progressions should implement
contains
and
indexOf
etc!
f

Florian

07/08/2019, 5:20 PM
What are you referring to exactly
k

karelpeeters

07/08/2019, 5:20 PM
Ah, but the range simply does a check where as the progression needs to loop through all the numbers to see if one matches
View count: 2