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

    alex.hart

    07/25/2019, 5:42 PM
    The most important questions have nothing to do with what tech you utilize. It’s how you architect your application. Your choice of template language, IDE, DB, etc, has no impact on that. Kotlin-React would not use templates. Generally with React style frameworks, everything is in one language (JS, Kotlin, Typescript, whatever). Separation of Concerns and adherence to other SOLID principles, etc. are totally in your hands. It sounds like you want: • An Android App • An iOS App • A Server Application • A Web Application Is that correct? I don’t see why this couldn’t be completely implemented in Kotlin if you really wanted to, there just might be some hiccups with Kotlin Native (but it is getting better all the time). KTOR for server, Kotlin multiplatform for mobile. There’s more to it than that, but honestly I’d start with one single aspect of what you’re trying to accomplish and build that out FIRST and then move on from there. Don’t try to learn every little piece of tech at once. Take your time.
    👍 1
    g
    t
    • 3
    • 15
  • s

    Steve

    07/25/2019, 5:44 PM
    Make things easy on yourself: Write the Android app in Kotlin using Android Studio, and the iOS app in Swift using Xcode. Using the default environments, especially for your first app, removes a lot of those decisions for you
    ➕ 2
    s
    • 2
    • 1
  • g

    geepawhill

    07/25/2019, 5:49 PM
    Folks, dumb question: Is there any way to use the delegation mechanism on a property that is not declared in the constructor? something like this:
    class X : List<Y> by myList { private val myList = mutableListOf<Y>()
    Failing that as a simple declaration, is the clever way to do it maybe make the primary constructor private and offer secondary constructors to call it?
    h
    k
    s
    • 4
    • 4
  • g

    Gunslingor

    07/25/2019, 5:56 PM
    I think I started a new thread... fairly new to slack too, lol, oh man I must be getting old... I miss the days of assembly, lol, jk
    s
    • 2
    • 5
  • f

    fangzhzh

    07/25/2019, 9:02 PM
    Hello, I have a math equation
    val result = value * 100.0 / 255
    Given that 100.0/255=0.392, is
    val result = value * 0.392
    better than the equation one in the performance of view.
    m
    k
    • 3
    • 10
  • a

    aurimas

    07/25/2019, 10:37 PM
    Is there a good channel (maybe even different slack instance) to ask questions about using PSI/UAST on koltin code? For example right now I'm struggling to figure out tell if a KotlinUParameter type is an inline type
    k
    v
    +2
    • 5
    • 5
  • v

    vpriscan

    07/26/2019, 8:10 AM
    My test so far uses no libraries except stdlib-jdk8 and RxKotlin
    :thread-please: 1
    h
    l
    • 3
    • 10
  • k

    KindRoacher

    07/26/2019, 8:37 AM
    Let's say, there 2 functions with same signature but one is with a default parameter and the other is not. When invoking one of the function, how does the compiler figure out which one to pick? because when invoking the function, we have then 2 choice, either call one without the default parameter or one with the default parameter. But even if we invoke the function with the default parameter, somehow the compiler still invokes the function without the default parameter. I checked the bytecode but I could get much answer from it. https://pastebin.com/nqfsFLHH
    h
    m
    • 3
    • 8
  • v

    vpriscan

    07/26/2019, 8:42 AM
    Why is ktor's HttpClient(OkHttp) marked red in Intellij?
    m
    k
    • 3
    • 5
  • j

    Jan

    07/26/2019, 12:44 PM
    is there a kotlin conccurent set? kinda only find java ones
    k
    s
    +2
    • 5
    • 7
  • t

    tenprint

    07/26/2019, 2:03 PM
    If I pass a method reference from Java to a Kotlin function, what do I put for parameter type? E.g.
    MyJavaClass {
      MyKotlinClass myKotlinClass;
    
      void myMethod() { ... }
    
      ... myKotlinClass.foo(this::myMethod);
    }
    What should be the parameter in
    fun foo( ? )
    ?
    d
    e
    s
    • 4
    • 7
  • t

    twisterrob

    07/26/2019, 6:22 PM
    I'm trying to write a seemingly simple function, but Kotlin doesn't play dice, what am I doing wrong? declaration:
    fun <E> Collection<E>.myContains(item: E) : Boolean
    usage:
    val isItInside: Boolean = listOf(1, 2).myContains("1")
    expectation: usage fails to compile, because it's a
    List<Int>
    vs. a
    String
    https://stackoverflow.com/q/57224118/253468
    s
    b
    +4
    • 7
    • 40
  • p

    pajatopmr

    07/27/2019, 7:39 AM
    I am trying to figure out how generate a null using simpleName. See this SO post: https://stackoverflow.com/questions/57229715/how-to-generate-a-null-using-kotlin-kclass-property-simplename
    k
    • 2
    • 8
  • c

    corneil

    07/27/2019, 12:25 PM
    Please add a reaction to vote: 1️⃣ Immutable comparator performs better 2️⃣ Classic mutable comparator performs better 0️⃣ No real difference
    Is_there_a_payoff_for_immutability_
    0️⃣ 7
    1️⃣ 2
    2️⃣ 2
    k
    g
    +2
    • 5
    • 27
  • i

    Ive Vasiljevic

    07/27/2019, 1:25 PM
    Can extension functions, which are offered by Kotlin, be seen as a replacement for Utility classes and by that utility methods? At least most of the time not always
    k
    l
    p
    • 4
    • 3
  • g

    Gunslingor

    07/27/2019, 9:17 PM
    https://github.com/eugenp/tutorials/blob/master/spring-mvc-kotlin/src/main/kotlin/com/baeldung/kotlin/mvc/ApplicationWebConfig.kt I'm having an issue following that. Not sure where to put it and some of this stuff is depreciated. I've got a REST API in main.kotlin.org.app.web.api.apiController and I'm trying to make main.kotlin.org.app.web.js.jsController; basically my @RestController is working perfectly but I can't seemt o get my HTML/js @Controller to work. I was thinking the view resolver needed to be configured or something? New to kotlin, spring boot and smart IDE development.
    g
    c
    • 3
    • 35
  • p

    Pablichjenkov

    07/28/2019, 5:42 AM
    I found myself doing bellow code very often when having a nullable variable in a class. Is there a less verbose pattern?
    class SomeClass {
     
        var aVar: OtherClass? = null
    
        fun aFunction() {
    
            aVar?.let {
                //doSomething with aVar since 'it' is not null
            } ?: run {
                //doSomething else when aVar is null
            }
    
        }
    
    }
    I know that I can do this:
    fun aFunction() {
    
        val aVarLocalCopy = aVar
    
        if (aVarLocalCopy != null) {
                //doSomething with aVarLocalCopy
        } else {
                //doSomething else when aVarLocalCopy is null
        }
    
    }
    But I don’t like the fact of creating one line of code to extract the thread safe local reference copy of aVarProperty. Any pattern or extension function to write above code shorter.
    s
    • 2
    • 4
  • v

    vpriscan

    07/28/2019, 11:38 AM
    how to enable new type inference for the compiler?
    :google: 1
    l
    r
    • 3
    • 7
  • d

    dave08

    07/28/2019, 2:07 PM
    How can I make an extension function to wrap this Java
    mappingFunction
    ...:
    @Nullable  V get(@NonNull K key, @NonNull Function<? super K, ? extends V> mappingFunction);
    I really don't know what could be wrong:
    suspend inline fun <reified K : Any, reified V : Any> Cache<K, V>.get(key: K, crossinline mappingFunction: suspend (K) -> V): V? =
    	get(key) { runBlocking { mappingFunction(it) } }
    it's probably related to the generics... 🤕
    d
    • 2
    • 8
  • c

    CLOVIS

    07/28/2019, 9:58 PM
    Let's say I want a collection, a deferred or whatever, of 2 types. Do you recommend:
    //1
    Something<Pair<A, B>>
    //2
    data class Other<A, B>(...)
    Something<Other<A, B>>
    //3
    typealias Other<A, B> = Pair<A, B>
    Something<Other<A, B>>
    I'm expecting that the answer is "it depends", what are some good examples to choose which one to use?
    d
    • 2
    • 6
  • k

    Kroppeb

    07/28/2019, 10:18 PM
    So this code wouldn't even do the thing I had planned, but still. Why is it asking for a return statement? Any code below this line should be marked as unreachable. The right part of the assignment returns
    Nothing
    . This doesn't happen if assigned to a new var/val
    l
    l
    • 3
    • 8
  • d

    Dennis Schröder

    07/29/2019, 9:00 AM
    I can not edit or run stuff on https://play.kotlinlang.org. Is it just me or does somebody else have the same issue?
    d
    m
    s
    • 4
    • 5
  • b

    bitkid

    07/29/2019, 9:42 AM
    which frameworks are you guys using when writing tests with junit5 which depend on docker? testcontainers? is there something out there which is a bit more kotlin'ish?
    t
    • 2
    • 1
  • w

    widar

    07/29/2019, 9:46 AM
    There is a spotify docker library?
    c
    • 2
    • 2
  • m

    Michał Kalinowski

    07/29/2019, 11:27 AM
    Hey, so I want use ProGuard for obfuscation but each time when I want use reflection I have in bytecode `LKotlin/Metadata'. And there are too much about objects that I want hide. Is there any way to get rid of it? Or I need use java reflection?
    d
    g
    • 3
    • 4
  • j

    Joffrey

    07/29/2019, 5:48 PM
    Any built-in way to create a
    Flow
    of lines from a
    File
    (on JVM)? I thought about several options, like: -
    FileReader(file).buffered().lineSequence().asFlow()
    (requires to close reader externally) -
    flow { FileReader(file).useLines { lines -> lines.forEach { emit(it) } } }
    (broken reader closure it early termination) But I believe that would be using the blocking file API behind the scenes. Is this OK, though? Should I implement my flow on top of
    AsynchronousFileChannel
    instead?
    t
    • 2
    • 3
  • i

    Imran/Malic

    07/29/2019, 6:51 PM
    How can I construct supertypes of a class/object in Kotlin?
    s
    • 2
    • 3
  • s

    Stefan Beyer

    07/30/2019, 1:01 PM
    [solved, see thread] I just found a funny edge case in the "when expression must be exhaustive" check:
    fun foo(a: Boolean, b: Boolean) = when { // "when expression must be exhaustive" error
        a == b -> "same"
        a -> "first"
        b -> "second"
        // this actually IS exhaustive:
        //  a | b | result
        // ---+---+--------
        //  0 | 0 | same
        //  1 | 0 | first
        //  0 | 1 | second
        //  1 | 1 | same
    }
    Do you guys think this is an issue that should be reported? 🙂 edit: I am not sure because surely this is just one example of a whole bunch of those cases and I personally would not want to implement thousands of corner cases into a language feature. (After all, this is a language, not platformer physics 😄)
    s
    j
    +2
    • 5
    • 26
  • s

    stellarspot

    07/30/2019, 1:17 PM
    The documentation about Inline Functions declares that
    inline
    is used as
    The inline modifier affects both the function itself and the lambdas passed to it: all of those will be inlined into the call site.
    
    In case you want only some of the lambdas passed to an inline function to be inline, you can mark some of your function parameters with the noinline modifier:
    What If I do not need to make the whole function inline but want that its passed lambdas are made inline? For example my function have private fields and to make it inline it is necessary to annotate the whole function with
    @Suppress("NON_PUBLIC_CALL_FROM_PUBLIC_INLINE")
    . If a function with lambda arguments is not marked as
    inline
    will the compiler smart enough to inline the lambda in the function body if the only lambda usage is its invocation? https://kotlinlang.org/docs/reference/inline-functions.html
    d
    i
    • 3
    • 5
  • i

    igor.wojda

    07/30/2019, 1:31 PM
    is
    prefix for Boolean returning methods is quite straight forward. I wonder what are you thoughts on adding
    is
    prefix to Boolean properties?
    // method
    view.isVisible()
    
    // property
    view.visible
    or
    view.isVisible
    k
    d
    +2
    • 5
    • 9
Powered by Linen
Title
i

igor.wojda

07/30/2019, 1:31 PM
is
prefix for Boolean returning methods is quite straight forward. I wonder what are you thoughts on adding
is
prefix to Boolean properties?
// method
view.isVisible()

// property
view.visible
or
view.isVisible
k

karelpeeters

07/30/2019, 1:39 PM
In this case I lean towards
visible
but it's an internal struggle every time 😒imple_smile:
d

dalexander

07/30/2019, 1:42 PM
I think at this point Kotlin has been in production too long to make that change, even if I would like to see it (I'm not a huge fan of property syntax in general, so I'm probably biased).
s

Stefan Beyer

07/30/2019, 1:45 PM
I personally prefer
view.isVisible
, but it depends on whether you need the accessors to be used (by java code or some lib like jackson)
// kotlin
class Foo(val cool:Boolean,val isHot:Boolean)

// java
public class Java {
    public static void main(String[] args) {
        Foo foo = new Foo(true, true);
        foo.getCool(); // not very cool :(
        foo.isHot();
    }
}
you could add
@getter:JvmName("isCool")
to the property, but this is uglier than in the first place ^^
k

karelpeeters

07/30/2019, 1:47 PM
@dalexander what change?
d

dalexander

07/30/2019, 1:49 PM
I was just thinking about how properties can be exposed which may not follow boolean naming conventions?
But it's slightly off topic from the original question I suppose. I do lean towards
isFoo
pretty heavily.
a

arekolek

07/30/2019, 2:14 PM
I write
isVisible: Boolean
rather than
visible: Boolean
Because of java interop, but also like I would write
hasChildren: Boolean
and not
children: Boolean
Also, there’s #codingconventions 😉
👍 1
i

igor.wojda

07/30/2019, 2:22 PM
Let’s assume Java is not there - pure Kotlin project
a

arekolek

07/30/2019, 3:13 PM
For example
view.takeIf { it.isVisible }
reads better than
view.takeIf { it.visible }
View count: 6