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

    muralimohan962

    10/31/2018, 6:31 AM
    coroutineScope { // Now you are in scope }
    i
    • 2
    • 4
  • f

    febs

    10/31/2018, 8:46 AM
    Hello all. I'm a beginner trying to learn something more advanced that the very basics. I got a question about "by lazy" assignment. Premising that one of the reasons to use a lazy assignment is to avoid making a val or var nullable in case you can't assign it a value right there right now (there are other reasons to defer it; but this is a common one). That being said, is it possible to lazily assign something which may actually return null to a nullable variable? Hope the question is clear. Thanks!
    p
    • 2
    • 1
  • f

    febs

    10/31/2018, 9:07 AM
    This. What is (and am I) missing here? Thanks so much ❤️
    m
    g
    • 3
    • 5
  • s

    sannysoft

    10/31/2018, 10:07 AM
    Hello. Is there a migration guide for coroutines 1.0.0? That’s pretty weird to have it experimental for year+ and then release a totally different implementation without deprecation and backward compatibility.
    l
    • 2
    • 1
  • i

    igor.wojda

    10/31/2018, 11:09 AM
    What is the easiest way to determine if
    list
    contains items with the same value (we don’t know what value it may be). Is there any operator or combination fo operators to achieve this ? eg `
    listOf("A", "A", "A")  //true
    listOf("A", "A", "B")  //false
    `
    👍 1
    e
    a
    +3
    • 6
    • 23
  • b

    buremba

    10/31/2018, 11:54 AM
    The reason that I'm asking is that we have such use-case, parse JSON and doesn't know the type of generics so we need to use
    Operator<*>
    . Jackson automatically parse the string into the appropriate class for that Operator so we're sure that it will work. What's the alternative approach to this use-case in Kotlin?
    p
    • 2
    • 1
  • h

    hudsonb

    10/31/2018, 11:55 AM
    Is there a minimum gradle version for kotlin 1.3?
    r
    g
    • 3
    • 15
  • a

    APXEOLOG

    10/31/2018, 12:47 PM
    Hello, any ideas how can i get the class of a generic parameter?
    abstract class Behavior<T> {
        fun getData(entity: Entity): T {
            return entity.getData(T::class)
        }
    }
    Got
    Cannot use T as reified type parameter
    g
    • 2
    • 1
  • s

    stevecstian

    10/31/2018, 1:11 PM
    http://kotlinlang.org/docs/reference/compatibility-guide-13.html#data-class-overriding-copy
    a
    • 2
    • 1
  • r

    rnathani

    10/31/2018, 1:12 PM
    Hello, I am new to kotlin and I was wondering if there is a way to destroy kotlin object so init block is reinitialized. This is for testing purpose?
    n
    c
    • 3
    • 3
  • n

    Nikita Khlebushkin

    10/31/2018, 2:27 PM
    I use lambda expressions/anonymous classes in my app (for example, for onClickListener) but it leads to memory leaks and nullifying all them seems to be pain. I was wondering if there is a laconic way that I could use instead lambda expressions/anonymous classes but without creating static classes for every case?
    m
    • 2
    • 1
  • e

    Egor Trutenko

    10/31/2018, 2:30 PM
    Again, what exactly do you nullify?
    n
    k
    • 3
    • 3
  • t

    Tom Adam

    10/31/2018, 3:04 PM
    I wonder if Kotlin will have sumBy and sum for List<BigDecimal> in the future? Useful in banking system, and one does not have to write his own:);)
    r
    m
    +3
    • 6
    • 15
  • k

    karelpeeters

    10/31/2018, 9:14 PM
    Answer is probably no but is there a way to either • reset a lateinit property back to null? • do it myself with a getter that returns non-null with
    !!
    and a setter that accepts null?
    r
    l
    • 3
    • 9
  • h

    Hamza

    11/01/2018, 12:42 AM
    Will Kotlin get syntax for list, set and map creation
    ☝️ 1
    s
    k
    m
    • 4
    • 12
  • h

    Hamza

    11/01/2018, 12:43 AM
    Or list = [[1, 2, 3]] for mutable ones
    s
    • 2
    • 1
  • h

    Hamza

    11/01/2018, 12:44 AM
    set = {1, 2, 3} mutableSet = {{1, 2, 3}}
    y
    • 2
    • 1
  • m

    Mark

    11/01/2018, 2:10 AM
    Hi - I’m experimenting with
    sequence {}
    but getting “Restricted suspending functions can only invoke member or extension suspending functions on their restricted coroutine scope”. I can’t seem to find any information about this. Any pointers please? https://pl.kotl.in/B1hRgy_2m Presumably I need to use a suspending extension function of CoroutineScope?
    g
    • 2
    • 23
  • h

    Hamza

    11/01/2018, 2:56 AM
    I’m really confused, in the Primitives.kt file in the kotlin stdlib, the minus function for Bytes is as follows:
    /** Subtracts the other value from this value. */
        public operator fun minus(other: Byte): Int
    Note: This is inside the byte class.
    g
    s
    • 3
    • 20
  • g

    gildor

    11/01/2018, 10:46 AM
    I remember someone already proposed this some time ago as part of the language
    e
    c
    • 3
    • 5
  • b

    Bernhard

    11/01/2018, 1:38 PM
    still would require you to make them delegated properties from the start
    k
    • 2
    • 1
  • s

    Spike Baylor

    11/01/2018, 2:16 PM
    i get lazy and observable and quite a few others, but I did wonder what was going on with
    by cssclass()
    is that really just a wrapper around some sort of lazy type opperation?
    k
    • 2
    • 3
  • n

    Nikky

    11/01/2018, 3:44 PM
    so, what is currently the best working code coverage tool for kotlin other than using idea itself ? that is not possible in github checks afaik inlined calls, extension functions and suspend functions are rather random in their coverage in jacoco
    s
    • 2
    • 3
  • t

    thanksforallthefish

    11/01/2018, 4:13 PM
    no idea where to ask this, but I am experimenting with inline classes. Quite awesome feature imo, except
    toString
    does not seem consistent (given my understanding that inline classes are substituted with their member) given
    inline class ProjectUid(val projectUid: String)
    println(ProjectUid("test"))
    the output is
    ProjectUid(projectUid=test)
    , I would have expected only
    test
    . This "breaks" some libraries (simple workaround is to inline myself) am I misundersting something? is this behavior expected?
    d
    l
    a
    • 4
    • 7
  • s

    Spike Baylor

    11/01/2018, 5:58 PM
    So i have thoroughly been enjoying learning Kotlin for the past month or so, but now I find myself routinely forgetting semicolons when i go back to java, js, or ts 😞
    💯 1
    d
    l
    +3
    • 6
    • 18
  • m

    marcelo

    11/01/2018, 6:59 PM
    when I execute this code, I expected to get a "false" but instead, I always get true. Not sure what I am doing wrong.
    metrics.timer(timerName, successTag).time {
                    throw IllegalArgumentException("Stop")`
    Timer1.kt
    s
    • 2
    • 18
  • g

    GarouDan

    11/01/2018, 11:31 PM
    Guys, if we are using an annotation that need to receive a string parameter, how could we assign the value on a way to work with kotlin? For example
    @Bean("MyBean") // works, but
    @Bean(MyBean::class.simplaname) // don't work, since the annotation says something like `An annotation argument must be a compile-time constant`
    Is there a way to contour this? Since the annotation will be compile-time constant to me. I would like do something like these to create a lot of dynamic values when using annotation classes.
    k
    • 2
    • 2
  • o

    Ovsyannikov Alexey

    11/02/2018, 1:25 AM
    Hello What can be changed with
    BroadcastChannel
    ? Now it is marked as
    experimental
    g
    • 2
    • 7
  • s

    Shawn

    11/02/2018, 2:32 AM
    I don’t recommend it, but yeah
    🙂 1
    w
    • 2
    • 1
  • h

    Hamza

    11/02/2018, 4:59 AM
    hi, is there more documentation on contracts? i’ve seen a bit of stuff, but not sometthing like what i am looking for. is that trying to confirm all of the varargs provided aren’t null:
    @UseExperimental(ExperimentalContracts::class)
    fun anyNotNull(vararg arguments: Any?, block: () -> Unit): Boolean {
        contract {
            returns(true) implies /* Something here that tells the compiler that all arguments are not null */
        }
        if(arguments.any { it == null }) {
            block()
            return false
        }
        return true
    }
    g
    • 2
    • 6
Powered by Linen
Title
h

Hamza

11/02/2018, 4:59 AM
hi, is there more documentation on contracts? i’ve seen a bit of stuff, but not sometthing like what i am looking for. is that trying to confirm all of the varargs provided aren’t null:
@UseExperimental(ExperimentalContracts::class)
fun anyNotNull(vararg arguments: Any?, block: () -> Unit): Boolean {
    contract {
        returns(true) implies /* Something here that tells the compiler that all arguments are not null */
    }
    if(arguments.any { it == null }) {
        block()
        return false
    }
    return true
}
g

gildor

11/02/2018, 5:06 AM
not sure that it’s supported. Probably KEEP is the best source of information about contrcats
h

Hamza

11/02/2018, 5:06 AM
kk
could i do something like this?
inline fun anyNotNull(vararg arguments: String?, block: () -> Unit) {
    if(arguments.any { !isNotNull(it) }) {
        block()
    }
}

@UseExperimental(ExperimentalContracts::class)
fun isNotNull(arg: String?): Boolean {
    contract { 
        returns(true) implies (arg != null)
    }
    return arg != null
}
aww, it didn’t work
g

gildor

11/02/2018, 5:18 AM
Maybe you could ask here: https://github.com/Kotlin/KEEP/issues/139
h

Hamza

11/02/2018, 5:18 AM
kk
View count: 3