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

    Ruckus

    09/16/2020, 3:02 PM
    Does the "hidden classes" feature of JVM 15 have potential improve Kotlin on the JVM?
    e
    i
    • 3
    • 8
  • z

    zeugederunity

    09/16/2020, 3:45 PM
    Hello everyone, after updating to Kotlin 1.4.10 i realized, that the
    SerialName
    annotation was set to
    retention(BINARY)
    Is there any way in Kotlin 1.4 to retrieve the
    SerialName
    of an annotated property? Because the way by reflection is now lost.
    l
    • 2
    • 3
  • m

    Marc Knaup

    09/16/2020, 6:39 PM
    Is there a way to override a property getter so that the backing field is
    const
    ? I.e.
    (FooFeature as Feature).id
    uses the property getter and
    FooFeature.id
    uses the compile-time constant
    n
    b
    • 3
    • 9
  • w

    weber de lima santos

    09/16/2020, 8:22 PM
    Hey dudes! Do i got it wrong, or the loadKoinModules works lazy ?
    z
    b
    • 3
    • 3
  • r

    Robert Menke

    09/16/2020, 8:26 PM
    Hey all, looking for an equivalent of android’s Base64InputStream I can use server-side. Is anyone aware of any open source implementations?
    z
    • 2
    • 2
  • l

    laith

    09/16/2020, 9:50 PM
    Hi all is it possible to get the class type of the lambda ? something like
    ((String) -> String)::class
    s
    r
    • 3
    • 5
  • m

    myaa

    09/17/2020, 12:13 AM
    how come smart casting doesn't work here? i get
    unresolved reference: value
    for the
    is Match.HasMatch
    line
    sealed class Match {
        object NoMatch : Match()
        class HasMatch(value: Int) : Match()
    }
    
    fun main() {
        val x: Match? = null
    
        when (x) {
            Match.NoMatch -> println("no match")
            is Match.HasMatch -> println("value: ${x.value}")
            null -> println("null")
        }
    }
    n
    • 2
    • 4
  • j

    Justin

    09/17/2020, 4:15 AM
    What is the appropriate way to write tests for an application that builds a command line tool (using
    kotlinx.cli
    )? The app itself looks pretty typical, e.g.:
    fun main(args: Array<String>) {
       // Do stuff that might exit with status code 0 or 1
    }
    My (apparently wrong) instinct was to write tests like:
    @Test fun testExitsWithoutError() {
       val result = main(args)
       assertEquals(0, result)
    }
    But
    main
    can only return
    void
    . How do I write tests that can pass args into main and expect a certain result?
    n
    j
    • 3
    • 21
  • b

    Brett Best

    09/17/2020, 9:49 AM
    What channel is best for discussing Jetpack DataStore?
    j
    • 2
    • 2
  • k

    Kurt Renzo Acosta

    09/17/2020, 10:44 AM
    My current data model uses nullables and a state property to handle the objects state
    data class Model(
        val a: String,
        val b: String,
        val nullableOnlyForStateA: String?,
        val state: State,
        val propForStateA: String?,
        val propForStateB: String?
    )
    I’m trying to use sealed classes to make it more idiomatic but it seems too verbose:
    sealed class Model {
        abstract val a: String
        abstract val b: String
        abstract val nullableOnlyForStateA: String?
    
        data class A(
            override val a: String,
            override val b: String,
            override val nullableOnlyForStateA: String?,
            val propForStateA: String
        ) : Model()
    
        data class B(
            override val a: String,
            override val b: String,
            override val nullableOnlyForStateA: String,
            val propForStateB: String
        ) : Model()
    }
    This seems okay but my original class has much more properties and more states making a 16-line data class turn into a more-than-100 line sealed class. Any ideas on how to make this more ergonomic?
    m
    n
    • 3
    • 20
  • w

    Will Nixon

    09/17/2020, 2:40 PM
    Hi all, wondering whether you all tend to include or exclude tax when you decide on pricing your apps in the app store? Is there a community consensus on the etiquette here?
    s
    s
    a
    • 4
    • 8
  • m

    Mgj

    09/17/2020, 3:09 PM
    Is there a good way of fixing kotlinx.serialization's handling of nullable values? This class...
    @Serializable
    data class MyDataClass(
        val myProp: String?
    )
    ... will throw
    kotlinx.serialization.MissingFieldException: Field 'myProp' is required, but it was missing
    if the json does not contain the
    myProp
    key. I really dont want to add a default value of
    null
    to every single optional field
    n
    • 2
    • 8
  • r

    Roger Sala

    09/17/2020, 3:27 PM
    Hi, im trying to program an android app for a school project. My idea is an app that contains exams and their corrections organized by subjects and with a pdf download option. Is that easy to do? Some help in how to start?
    m
    • 2
    • 1
  • u

    user

    09/17/2020, 3:30 PM
    message has been deleted
    n
    b
    • 2
    • 10
  • k

    Karlo Lozovina

    09/17/2020, 10:21 PM
    is there a way to refer to
    when
    condition without binding it to a name? some sort of default provided name? For example in the code below, is it possible to write it without the
    temp
    variable?:
    val temp = foo.bar.getBaz()
    when (temp) {
    is A -> print(temp)
    is B -> ...
    }
    s
    • 2
    • 3
  • c

    Colton Idle

    09/18/2020, 3:16 AM
    Currently using kotlin 1.4.10 in my android project. Is there an EAP or someway to try 1.4.20 early? I want to see if it fixes a compilation issue I'm having. I tried looking here https://kotlinlang.org/eap/ but only see a 1.4.0 rc.
    j
    e
    +2
    • 5
    • 5
  • k

    KayCee

    09/18/2020, 3:52 AM
    How can I add all 3 lists of object into one? Given the first and the third one can be empty? There ain't something like listA.addAll(listB).addAll(listC) 🤔
    d
    n
    • 3
    • 7
  • d

    Daniel Svensson

    09/18/2020, 6:55 AM
    kotlin-test's assertNotNull lets the compiler know that whatever is passed to it is not null afterwards, while junit's assertNotNull does not. Why is it like that?
    c
    p
    • 3
    • 4
  • e

    elect

    09/18/2020, 8:03 AM
    one user is getting with one of out lib the following:
    java.lang.LinkageError: loader constraint violation: when resolving method "imgui.ImGui.begin(Ljava/lang/String;Lkotlin/reflect/KMutableProperty0;I)Z" the class loader (instance of net/fabricmc/loader/launch/knot/KnotClassLoader) of the current class, net/aaa/bbbb/gui/screen/ModScreen, and the class loader (instance of sun/misc/Launcher$AppClassLoader) for the method's defining class, imgui/ImGui, have different Class objects for the type kotlin/reflect/KMutableProperty0 used in the signature
    since he updated from 1.4.0 to 1.4.10, has anyone encountered something similar?
    p
    n
    • 3
    • 9
  • i

    Isaac

    09/18/2020, 11:10 AM
    So I defined a property in
    gradle.properties
    file and got a reference in the
    build.gradle.kts
    file by declaring a global property:
    val api_key: String by project
    . I want to use
    api_key
    in my
    Main.kt
    , but I can't seem to figure out how to gain access. Searched on StackOverflow and all the results were android related. Can anyone help?
    d
    s
    m
    • 4
    • 4
  • s

    spand

    09/18/2020, 2:43 PM
    I am trying to get SAM conversion working. Why do I get errors right side of assignment in both
    foo2
    ,
    foo3
    ?
    interface Foo {
        fun bar()
    }
    
    private val foo: Foo = object : Foo {
        override fun bar() {
            TODO("Not yet implemented")
        }
    }
    
    private val foo2: Foo = {}
    private val foo3: Foo = Foo {}
    j
    s
    +2
    • 5
    • 19
  • a

    andylamax

    09/18/2020, 2:56 PM
    where can I follow the progress of the IR backend? I wan't to know when it's scheduled to leave alpha
    u
    d
    b
    • 4
    • 4
  • l

    LeoColman

    09/18/2020, 2:57 PM
    Hey guys! What are you using to measure code coverage? Jacoco doesn't have a very nice integration with Kotlin, marking inline functions as uncovered, for example, and others
    👀 1
    k
    • 2
    • 4
  • n

    Nir

    09/18/2020, 3:34 PM
    Is there a way to add your own "prelude" that's automatically present in every file? For example, suppose you want to replace the standard library
    map
    with your own that returns an ImmutableList instead of a List. How would you do it?
    a
    j
    +2
    • 5
    • 116
  • v

    Vivek Subramanian

    09/18/2020, 5:07 PM
    Hi, I just started playing around with KMM today - I am having trouble running the ios simulator from Android studio. Is this the right place to ask for help?
    n
    k
    • 3
    • 3
  • s

    Shawn

    09/18/2020, 5:09 PM
    It looks like #kmm exists as a channel but hasn’t gotten a whole lot of traction yet
    k
    • 2
    • 1
  • n

    Nir

    09/18/2020, 7:01 PM
    Trying to use kotlinx immutable collections. As it says, I've added
    implementation "org.jetbrains.kotlinx:kotlinx-collections-immutable-jvm:0.3.3"
    to my gradle file, but it still can't seem to import. How should I debug this?
    h
    • 2
    • 7
  • s

    Simon Kågedal Reimer

    09/19/2020, 7:22 PM
    Hello! If I have a function that takes a callback that is called with a parameter, and for some callback I do not need or use this parameter – the only way to not get warnings about this is to use a @Suppress annotation, is this correct?
    fun myCallback(@Suppress("UNUSED_PARAMETER") someValue: Int) { }
    n
    • 2
    • 4
  • n

    Nir

    09/20/2020, 2:21 AM
    Is there a way in Kotlin, when I import something into a package, to make it so that it in turn becomes available for import from that package? e.g. say my package
    foo
    imports
    bar.blub
    , i want it to to be so that if somoene does
    import foo.*
    they also get blub.
    s
    l
    f
    • 4
    • 12
  • a

    Ayden

    09/20/2020, 3:15 PM
    Hi everyone. https://github.com/gastsail/CocktailApp/tree/master/app/src/main/java/com/g/tragosapp/domain According to this repo, the developer extract the interface and the actual implementation to different files. Does this approach has any name?
    v
    z
    • 3
    • 11
Powered by Linen
Title
a

Ayden

09/20/2020, 3:15 PM
Hi everyone. https://github.com/gastsail/CocktailApp/tree/master/app/src/main/java/com/g/tragosapp/domain According to this repo, the developer extract the interface and the actual implementation to different files. Does this approach has any name?
v

Vampire

09/20/2020, 3:28 PM
Good design? :-D
"Coding to interfaces" is one of the phrases describing it partly
☝️ 2
You can easily swap the implementations if you just used the interfaces, like
List
vs.
ArrayList
,
LinkedList
, ...
z

Zach Klippenstein (he/him) [MOD]

09/20/2020, 4:38 PM
I don't know if there's a name for specifically putting the interface and implementation in different files. But I've heard the pattern of logically separating the code called simply "the interface/impl pattern". But it also relates to other patterns such as dependency inversion.
a

Ayden

09/21/2020, 1:17 AM
I see. Thank you @Vampire @Zach Klippenstein (he/him) [MOD]
@Vampire not sure if this is a good design or not. But I heard from other it helps on creating test case.
v

Vampire

09/21/2020, 9:38 AM
It can, as I said. If you stick to interfaces, you can easily swap implementations and then for example give a mock instead that implements the same interface.
a

Ayden

09/24/2020, 4:25 PM
@Zach Klippenstein (he/him) [MOD] I found the name of this pattern.
Bridge pattern
. https://en.wikipedia.org/wiki/Bridge_pattern
v

Vampire

09/24/2020, 5:15 PM
Not really. Did you actually read the book, or the wiki page?
a

Ayden

09/25/2020, 1:28 AM
@Vampire yeah. I actually read the short description and went through the SO to understand it. Am I missing something?
v

Vampire

09/25/2020, 10:00 PM
Yes, read it again. :-) The wiki article explains it better than I could.
View count: 2