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

    PHondogo

    05/08/2020, 10:56 AM
    Hello! In my java code I have method
    void test(Consumer<Test> consumer)
    When I call it from kotlin
    test{ it.doSmth() }
    What should I do to be abble to call it from java like this
    test{ this.doSmth() }
    so it must behave as extension function lambda
    d
    k
    • 3
    • 4
  • s

    Subhi Pandey

    05/08/2020, 5:42 PM
    I am the organizer of Kotlin community in Mumbai, India
    m
    • 2
    • 1
  • e

    E.Kisaragi

    05/08/2020, 9:07 PM
    are there any advantages using Optional rather than nullable type?
    s
    s
    +2
    • 5
    • 14
  • s

    supra

    05/09/2020, 2:52 AM
    output like this:
    val list = listOf("A", "B", "C")
    var str = "";
    list.forEachIndexed() {index , element ->
        str += " [$index:$element]"
    }
    d
    a
    • 3
    • 3
  • h

    Hullaballoonatic

    05/09/2020, 3:47 PM
    i don't mean this condescendingly: what is the point of SAMs in kotlin? why not just write a top-level method? inheritance (guessing no)? java compatibility (guessing yes)?
    a
    • 2
    • 1
  • k

    Kroppeb

    05/09/2020, 5:23 PM
    Why does Kotlin compile
    (Entity)->Boolean
    to just a
    Function1<Entity, Boolean>
    and not to something that doesn't require boxing like `Predicate<Entity`>?
    j
    e
    • 3
    • 8
  • a

    ahmad

    05/09/2020, 10:27 PM
    I want to create an annotation that can accept a param with different types.
    annotation class Decimal(val value: Int)
    I mean the
    value
    type could be for example,
    Int
    ,
    BigInteger
    , or
    BigDecimal
    What do you think the best approach to do this?
    k
    • 2
    • 4
  • e

    elect

    05/10/2020, 8:19 AM
    I'm trying to pack an
    Int
    as a
    Short
    in the upper part of a
    Long
    , but I get an out of range on declaring an hexadecimal number
    val l = (value.toLong() shl 48) and 0xffff_0000_0000_0000  // Error:(103, 42) Kotlin: The value is out of range. Expected: Long. Found: Int
    How can I solve? Casting to
    Long
    doesnt help
    i
    d
    • 3
    • 8
  • e

    elect

    05/10/2020, 8:27 AM
    shouldnt postfix
    u
    help maybe? (this works though
    (0xffff shl 48)
    )
    c
    u
    • 3
    • 5
  • m

    Marc Knaup

    05/10/2020, 4:48 PM
    Why does
    foo.value
    resolve to
    Any?
    and not the upper bound
    Bar
    ?
    t
    t
    • 3
    • 5
  • l

    LS

    05/11/2020, 12:15 AM
    Shouldn't foo be smart cast to non-null in the second condition?
    c
    d
    s
    • 4
    • 11
  • b

    bod

    05/11/2020, 8:49 AM
    Hello, World! Hey I was looking at contracts again (even though they're still experimental), and couldn't find a way to do what I want, so I'm wondering if it's possible. I have a
    fun parseDate(dateStr: String?): Date?
    and want to express that if
    dateStr
    is
    null
    then the result will be
    null
    - and also the opposite. Possible?
    r
    d
    • 3
    • 7
  • p

    pavankumar

    05/11/2020, 9:22 AM
    Hello, I want to know why the below code is throwing exception to the console even though i'm handling it using "CoroutineExceptionHandler"?
    fun main() = runBlocking {
    with(CoroutineScope(coroutineContext + CoroutineExceptionHandler { _, _ ->  println("Exception")})) {
    val firstChild = launch() { // if i add "CoroutineExceptionHandler here, then launch coroutine will handle exception without printing on console
    println("First child is failing")
    delay(1000)
    throw AssertionError("First child is cancelled")
    }
    // launch the second child
    val secondChild = launch {
    println("First child is cancelled: ${firstChild.isCancelled}, but second one is still active")
    try {
    delay(Long.MAX_VALUE)
    } finally {
    println("Second child is cancelled")
    }
    }
    secondChild.join()
    }
    }
    a
    • 2
    • 1
  • j

    Jaro

    05/11/2020, 10:02 AM
    Hi all, I have question regarding annotations. Assume a following example
    open class A(val strings: List<String>)
    
    class B(strings: List<String>) : A(strings)
    
    class C(strings: List<String>) : A(strings)
    these classes are used in my REST API and I would like to validate their content with JSR annotations. I want to check that the collection
    strings
    in class
    B
    is not empty using
    @NotEmpty
    but I can apply this validation only on the property declaration (if I’m not mistaken). What is the best Kotlin way to add this validation to class
    B
    ? In java I would probably override getter in class B and add annotation there, can I do something similar in Kotlin?
    j
    t
    a
    • 4
    • 11
  • i

    iex

    05/11/2020, 1:26 PM
    I guess this function would do
    inline fun <reified T> listWith(count: Int, element: T): List<T> =
        Array(count) { element }.toList()
    m
    l
    • 3
    • 5
  • f

    FranSoto

    05/11/2020, 1:26 PM
    https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/fill.html
    i
    • 2
    • 1
  • l

    LastExceed

    05/11/2020, 1:40 PM
    can someone confirm or correct my understanding of programming terminology? identifier: things that programmers can choose a name for object: (not the kotlin keyword specifically but in general) group of identifiers member: direct child of an object class: identifier that blueprints an object singleton: class that can only produce a single object which is accessed as if the class IS the object variable: identifier that stores a value field: member variable property: field with getter and setter attribute: vague term, does not have a unique definition function: identifier for which i dont find the right words to describe it method: member function lambda: nameless function closure: lambda that captures it's context
    m
    r
    • 3
    • 6
  • l

    LeoColman

    05/11/2020, 3:38 PM
    Hey guys! When talking about Kotlin libraries, there's a specific part in the code style that states
    Always explicitly specify function return types and property types (to avoid accidentally changing the return type when the implementation changes)
    It's kind of ambiguous for me if it applies to
    Unit
    as well. As I understand, it's meant for
    fun test(someVar:String) = when(someVar){
     "a" -> 10
     else -> 20
    }
    where you can easily break the Int return. Would we always specify that a certain method returns Unit, even if it's redundant?
    a
    • 2
    • 1
  • w

    Will Harrison

    05/11/2020, 5:37 PM
    Is Kotlin an extension of Java or is it it’s own separate language?
    s
    e
    +2
    • 5
    • 5
  • h

    Hexa

    05/12/2020, 7:12 AM
    Anyone else saw the above tweet? Not unpopular to me.
    r
    • 2
    • 1
  • r

    Robert Jaros

    05/12/2020, 11:18 AM
    I'm trying to use
    1.4-M1
    and I'm getting this warning from gradle:
    w: Runtime JAR files in the classpath should have the same version. These files were found in the classpath:
        /opt/rjaros/.gradle/wrapper/dists/gradle-6.3-all/b4awcolw9l59x95tu1obfh9i8/gradle-6.3/lib/kotlin-stdlib-1.3.70.jar (version 1.3)
    ...
        /opt/rjaros/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib/1.4-M1/1bd127486717887634cc406a5651bd6090f11678/kotlin-stdlib-1.4-M1.jar (version 1.4)
    w: Consider providing an explicit dependency on kotlin-reflect 1.4 to prevent strange errors
    w: Some runtime JAR files in the classpath have an incompatible version. Consider removing them from the classpath
    Should I ignore this or somehow fix this?
    c
    m
    • 3
    • 4
  • g

    Gopal S Akshintala

    05/12/2020, 1:32 PM
    Is there a way to find out and configure, which version of Kotlin does this language server uses? https://github.com/fwcd/kotlin-language-server
    c
    • 2
    • 1
  • r

    Ruckus

    05/12/2020, 3:25 PM
    What does the new "delegate to another property" get you over a custom getter/setter?
    i
    • 2
    • 2
  • a

    Antoine Gagnon

    05/12/2020, 4:18 PM
    Hi everyone! I want to be able to listen to changes on a variable and be able to publish new value to this variable. I’m wondering what would be the best thing to use without relying on RxJava (to use Subject) I’m torn between LiveData and ConflatedBroadcastChannel, any idea what the best one is?
    j
    a
    • 3
    • 4
  • o

    Orhan Tozan

    05/12/2020, 5:16 PM
    A quick silly question, subjecting kotlinx.serialization: is it recommended to create one Json() instance and inject it throughout your project or create a new one on every use?
    d
    • 2
    • 1
  • s

    spierce7

    05/12/2020, 6:12 PM
    Something that’s always stumped me. Why do anonymous inner classes in Kotlin start with
    object
    ? That seems to be a misnomer to me, and that it should be
    class
    instead. What am I missing?
    z
    s
    +4
    • 7
    • 13
  • l

    Leon johnson

    05/13/2020, 3:32 AM
    Hey guys I'm trying to create an app and inside of my ViewModel I have firebase authentication and database set up inside of it. I'm having trouble with creating a callback for my UI. So what I'm trying to do is create an user in my viewmodel and once that's done return that success to my UI so that it can transition to the next activity. Is there a way to do this?
    :stackoverflow: 4
    k
    • 2
    • 1
  • p

    pajatopmr

    05/13/2020, 12:00 PM
    Due to the pandemic I find myself, as I'm sure lots of you as well, doing remote pairing or mobbing sessions. Zoom + IntelliJ give very mixed results when sharing a screen. My results have been deplorable with my keystrokes just not working or doing strange things entirely. I've had much better success with VSCode (I am truly sorry to say) but VSCode with Kotlin is still very early days especially for quickly spotting errors or suspect code. For that IntelliJ cannot be beat. But VSCode has Live Share which makes collaborating very easy and makes my keystroke issues gone. I even can use Emacs keybindings and still work flawlessly with others. So all this boils down to two questions: 1) has anyone figured out how to use Kotlin and VSCode that puts it on a par with IntelliJ for basic development (detect and show error/warnings and run tests); 2) has anyone figured out how to pair/mob remotely with Kotlin seamlessly?
    g
    p
    +2
    • 5
    • 6
  • k

    Kevin

    05/13/2020, 5:25 PM
    Hi everyone! thanks for accepting me to the channel, i'm a beginner on kotlin, especially android programming. i hope i can learn a lot of things about android programming and we can work together in the future.
    s
    • 2
    • 1
  • b

    Brian Dilley

    05/13/2020, 7:15 PM
    when JetBrains was building the new IR for Kotlin 1.4 - did they consider LLVM? I don’t know a bunch about this sorta thing so I could be asking a dumb question… just curious.
    s
    d
    m
    • 4
    • 8
Powered by Linen
Title
b

Brian Dilley

05/13/2020, 7:15 PM
when JetBrains was building the new IR for Kotlin 1.4 - did they consider LLVM? I don’t know a bunch about this sorta thing so I could be asking a dumb question… just curious.
s

serebit

05/13/2020, 7:17 PM
Considering Kotlin/Native actually uses LLVM IR, I'd say they most likely did consider it! 😛
👍 2
d

Dominaezzz

05/13/2020, 7:17 PM
The new IR is LLVM agnostic, it more or less represents pure Kotlin. Kotlin/Native was built with the new IR infrastructure from the ground up, so yes.
❓ 1
b

Brian Dilley

05/13/2020, 7:18 PM
cool
so then Kotlin Native is Kotlin -> Kotlin IR -> LLVM IR -> Native code? And basically anything that LLVM can target can be targeted with Kotlin?
d

Dominaezzz

05/13/2020, 7:21 PM
Pretty much. (Assuming the runtime can fit on the target)
m

Markus Böck

05/13/2020, 7:26 PM
LLVM IR is probably much much much lower than the IR they built
d

Dominaezzz

05/13/2020, 8:58 PM
Coming from someone who has played with LLVM IR. It's not that much lower. It's just a bit lower.
m

Markus Böck

05/13/2020, 9:03 PM
I have no clue about Kotlin IR but LLVM IR is basically like assembly with explicit stack allocation and inifite registers
View count: 3