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

    CFrei

    09/20/2020, 3:30 PM
    Hi everybody, published two super short articles about some Kotlin features on medium and would like to know your opinions. Is that something someone wants to read? https://medium.com/swlh/kotlin-experiments-execution-after-return-ea919f239c4?source=friends_link&sk=f95e650bae29a901bab2f0ab33dfd519 https://medium.com/swlh/kotlin-for-lunch-atomic-t-261351048fad?source=friends_link&sk=28ebe47952f209e552482dfdbad27f49
    d
    z
    3 replies · 3 participants
  • e

    elect

    09/21/2020, 9:32 AM
    is there another way to loop an ArrayList in reverse (from last to first) without creating additional lists (such as
    .reversed()
    ) other than
    for(i in g.windows.lastIndex downTo 0) {
        val window = g.windows[i]
    ? Ps: I do need
    continue
    and
    break
    inside
    b
    p
    +1
    14 replies · 4 participants
  • r

    Romavic

    09/21/2020, 12:11 PM
    This is a library that allows you to spell out the htpp status codes extensively. https://github.com/Romavic/HttpStatusCode
    g
    5 replies · 2 participants
  • h

    Henry

    09/21/2020, 1:12 PM
    question on Kotlin generics if anyone thinks they might be able to help! https://stackoverflow.com/questions/63992988/instantiating-classes-from-non-reified-type-parameters
    e
    17 replies · 2 participants
  • m

    Mihael

    09/21/2020, 1:20 PM
    Hey guys, is there anyway i can make IntelliJ auto collapse kotlin doc comments like i can with java?
    t
    4 replies · 2 participants
  • a

    Alberto

    09/21/2020, 8:42 PM
    When calling a "suspend" method from Java we can use CompletableFuture, is there a similar Java counterpart when calling a method that returns a Flow<>?
    a
    z
    +1
    6 replies · 4 participants
  • n

    nanodeath

    09/22/2020, 5:00 AM
    why does
    foo::class
    return
    KClass<out String>
    instead of
    KClass<String>
    , and...what are my options if I actually want the latter?
    d
    10 replies · 2 participants
  • l

    Luc Girardin

    09/22/2020, 9:45 AM
    Hi folks! I bumped into the following issue while trying to port a Java library to Kotlin while keeping JVM API compatibility (i.e. this is why changing the name of the property or the function is not an adequate workaround for me). Here is a prototypical example of the issue:
    import kotlin.jvm.JvmField
    
    open class X(
        @JvmField
        open val x : Int = 0,
    ) {
        fun getX() : Int = x
    }
    
    open class XY(
        @JvmField
        val y : Int = 0
    ) : X()
    Trying to compile this little piece of code for the JVM will produce the following error:
    Inherited platform declarations clash: The following declarations have the same JVM signature (getX()I):
        fun <get-x>(): Int defined in XY
        fun getX(): Int defined in XY
    It seems that the @JvmField defined in X is not inherited by the XY class. From my perspective, this construct is valid and very useful if one want to keep compatibility with an API that offers both field and method-based access... even though this is usually bad yet common practice. Thanks for listening! Luc
    t
    n
    8 replies · 3 participants
  • b

    Bor Monty

    09/22/2020, 1:55 PM
    Is there a seperate chat for kotlin native?
    j
    3 replies · 2 participants
  • u

    user

    09/22/2020, 3:04 PM
    message has been deleted
    n
    1 reply · 1 participant
  • j

    Jakob K

    09/22/2020, 4:40 PM
    Why isn't it possible to pass an object of the type 
    ZusammenfassungABC
     , even if it inherits from 
    ZusammenfassungAC
     (line 22)?
    Unbenannt
    d
    z
    +2
    10 replies · 5 participants
  • k

    Karlo Lozovina

    09/23/2020, 1:21 PM
    lateinit
    has
    isInitialized
    to check if the field has been initialized, is there something similar for
    Delegates.notNull
    ?
    t
    b
    3 replies · 3 participants
  • j

    janvladimirmostert

    09/23/2020, 7:23 PM
    Is there a mechanism in Kotlin that could trigger the init on an object / class without having to call a blank function?
    class TestClass {
    
    	init {
    		println("????????????")
    	}
    
    	companion object {
    		init {
    			println("!!!!!!!!!!!!!")
    		}
    
    		fun touch() {
    			// empty function to trigger init
    		}
    	}
    }
    
    object TestObject {
    	init {
    		println(">>>>>>>>>>>>>>>>>")
    	}
    
    	fun touch() {
    		// empty function to trigger init
    	}
    }
    In my main, i literally have to call touch before the TestObject and TestClass' init is called
    @JvmStatic
    	fun main(args: Array<String>) {
    		TestClass.touch()
    		TestObject.touch()
    	}
    i'm tryin to implement some form of inversion of control where classes register themselve to a central place My use-case is building the equivalent of a Controller, but instead of wiring in URLs in a central place, each Controller wires itself in to the central point
    n
    b
    19 replies · 3 participants
  • l

    Louis Saglio

    09/23/2020, 7:50 PM
    Is there in the standard library (or an external one) a fucntion similar to
    random.choices
    in python ?
    n
    e
    84 replies · 3 participants
  • s

    spand

    09/24/2020, 8:07 AM
    Easily overused though
    m
    t
    +2
    18 replies · 5 participants
  • d

    Daniel Svensson

    09/24/2020, 9:57 AM
    Is there any working Kotlin IDE? I'm losing my mind in IDEA. The Kotlin plugin breaks all day long. Completely unusable, and it feels like it has gotten worse.
    d
    v
    7 replies · 3 participants
  • d

    Daniel Svensson

    09/24/2020, 9:59 AM
    Just tried latest 2020.3 EAP and no improvement there either. Constantly red blink in the right corner signalling exception in the Kotlin plugin. Organize import duplicating the last import >50% of the times, and if I'm unlucky, it also smashes up all imports on one single line.
    ➕ 1
    n
    v
    4 replies · 3 participants
  • d

    Daniel Svensson

    09/24/2020, 9:59 AM
    I like the language, but the tooling really tries its best to fend off users 😞
    n
    m
    +1
    10 replies · 4 participants
  • m

    mikehearn

    09/24/2020, 11:26 AM
    Is there a way to stop
    internal
    members showing up in auto-completion from Java projects?
    ➕ 3
    l
    1 reply · 2 participants
  • m

    mikehearn

    09/24/2020, 11:26 AM
    I thought they used to be marked as synthetic in the bytecode to prevent this, however, it seems to not (any longer ?) be the case. This is a big pain for us when building APIs in Kotlin
    u
    l
    4 replies · 3 participants
  • a

    Animesh Sahu

    09/24/2020, 2:21 PM
    Okay so I have a class:
    class ElementRemoveEvent<E>(
        val element: E,
        override val collection: ObservableCollection<E>
    ) : Event<E>
    And it is misbehaving as you can see in the screen shots, what is causing this and how do I get rid of it? Is it outcome of excessive type inference?
    t
    5 replies · 2 participants
  • a

    Animesh Sahu

    09/24/2020, 3:40 PM
    Since Kotlin has a strong type-inference, and seems like compiler already know the type which has to be received as parameter to lambda (in the function call), is it possible to reduce the redundant generic E of EventE, and the second generic parameter E itself?
    a
    5 replies · 2 participants
  • v

    vineethraj49

    09/24/2020, 4:25 PM
    hi; I have the following issue: library A; 1.0.4
    data class Test(
      val a: String,
      val b: String? = null
    )
    library A; 1.0.5
    data class Test(
      val a: String,
      val b: String? = null,
      val c: String? = null
    )
    library B; 1.0.1 -> library A; [1.0, 2.0) // when built -> 1.0.4 library C; -> library B; [1.0, 2.0) -> library A; [1.0, 2.0) now, when building library C again; -> library B; [1.0, 2.0) -> 1.0.1 -> library A; [1.0, 2.0) -> 1.0.5 here; given library A; 1.0.5 gets picked; the library C, when running, gives me
    java.lang.NoSuchMethodError: Test.<init>
    when it should've ideally not (I think?) can someone help me figure out why this is happening, and how I can mitigate this?
    n
    e
    +1
    8 replies · 4 participants
  • e

    Emmanuel Oga

    09/25/2020, 3:29 AM
    I'm confused about something. In many places the compiler just returns the last thing of a scope, like in lambdas, but sometimes I'm asked to return explicitly by the compiler. What's the rule for returning the last thing in the scope vs requiring an explicit return?
    n
    n
    +1
    26 replies · 4 participants
  • b

    bodiam

    09/25/2020, 6:01 AM
    Hi all. I was wondering if there’s a nice way to do something like:
    val myObject: MyClass? = map.ifKeyPresent("xyz) { return MyClass(it }.orElse { null }
    So, basically, if a map contains the key, convert the value of that key to a different type, and if it’s not there, return something else, for example
    null
    . Does something like this exist?
    v
    t
    +1
    8 replies · 4 participants
  • l

    louiscad

    09/25/2020, 7:46 AM
    Would you like a channel named
    naming
    for the community to give and receive code naming help? I'm thinking about code related names like symbols (functions, properties, classes, constants…), packages, modules, libraries, etc.
    :yes: 6
    c
    6 replies · 2 participants
  • b

    Bilel El Oud

    09/25/2020, 9:34 AM
    Hello, I am new and want to know which course I should start learning kotlin ? thank you
    g
    a
    2 replies · 3 participants
  • a

    Animesh Sahu

    09/25/2020, 5:04 PM
    Why is there no half implicit generics? Like if there's something like
    fun <T, E : SomeType<T>> function() {}
    Then both T and E needed to be specifed And for example this:
    fun <T, E : SomeType<T>> function(v: T) {}
    if we pass
    function(5)
    (T) as one of the parameter then E is automatically taken as SomeType<T>, but why cannot we have half implicit parameter like
    function<Int>()
    that could implicitly say about the second parameter? Or does it exist, I'm just not noticing it?
    👆 2
    n
    a
    +3
    42 replies · 6 participants
  • c

    Cole K

    09/25/2020, 8:59 PM
    Hey guys! I have this annotation
    @Retention(AnnotationRetention.RUNTIME)
    @Target(AnnotationTarget.FUNCTION)
    annotation class Navigate
    Being used like
    @Feature(Features.Login::class)
    object Login: FeatureModel() {
        override var featureItem = Config::loginFeature
        override var action = ".login.open"
        override var fallbackDisplayName = "Login"
        override var requiresLogin = false
        override var version = "1"
    
        @Navigate
        fun newInstance(): Intent {
            return Intent("TEST")
        }
    }
    But
    Login::class.declaredFunctions.map { it.annotations }
    Returns null in the evaluator. Any thoughts?
    n
    3 replies · 2 participants
  • g

    Gabriel Santos

    09/25/2020, 9:25 PM
    Hey guys, I'm currently working on a modular project that has 2 submodules,
    :core
    and
    :common
    , both of them are multiplatform supporting all existent platforms. But when I try to add :common as a dependency to core, the build doesn't fail, but it's not imported, here's my build.gradle.kts in :core
    plugins {
        kotlin("multiplatform") apply true
    }
    
    repositories {
        mavenCentral()
    }
    
    dependencies {
        implementation(project(":common"))
    }
    
    kotlin {
        jvm {
            compilations.all {
                kotlinOptions.jvmTarget = "1.8"
            }
        }
        js {
            browser {
                testTask {
                    useKarma {
                        useChromeHeadless()
                        webpackConfig.cssSupport.enabled = true
                    }
                }
            }
        }
        val hostOs = System.getProperty("os.name")
        val isMingwX64 = hostOs.startsWith("Windows")
        val nativeTarget = when {
            hostOs == "Mac OS X" -> macosX64("native")
            hostOs == "Linux" -> linuxX64("native")
            isMingwX64 -> mingwX64("native")
            else -> throw GradleException("Host OS is not supported in Kotlin/Native.")
        }
    
    
        sourceSets {
            val commonMain by getting
            val commonTest by getting {
                dependencies {
                    implementation(kotlin("test-common"))
                    implementation(kotlin("test-annotations-common"))
                }
            }
            val jvmMain by getting
            val jvmTest by getting {
                dependencies {
                    implementation(kotlin("test-junit"))
                }
            }
            val jsMain by getting
            val jsTest by getting {
                dependencies {
                    implementation(kotlin("test-js"))
                }
            }
            val nativeMain by getting
            val nativeTest by getting
        }
    }
    e
    3 replies · 2 participants
Powered by Linen
Title
g

Gabriel Santos

09/25/2020, 9:25 PM
Hey guys, I'm currently working on a modular project that has 2 submodules,
:core
and
:common
, both of them are multiplatform supporting all existent platforms. But when I try to add :common as a dependency to core, the build doesn't fail, but it's not imported, here's my build.gradle.kts in :core
plugins {
    kotlin("multiplatform") apply true
}

repositories {
    mavenCentral()
}

dependencies {
    implementation(project(":common"))
}

kotlin {
    jvm {
        compilations.all {
            kotlinOptions.jvmTarget = "1.8"
        }
    }
    js {
        browser {
            testTask {
                useKarma {
                    useChromeHeadless()
                    webpackConfig.cssSupport.enabled = true
                }
            }
        }
    }
    val hostOs = System.getProperty("os.name")
    val isMingwX64 = hostOs.startsWith("Windows")
    val nativeTarget = when {
        hostOs == "Mac OS X" -> macosX64("native")
        hostOs == "Linux" -> linuxX64("native")
        isMingwX64 -> mingwX64("native")
        else -> throw GradleException("Host OS is not supported in Kotlin/Native.")
    }


    sourceSets {
        val commonMain by getting
        val commonTest by getting {
            dependencies {
                implementation(kotlin("test-common"))
                implementation(kotlin("test-annotations-common"))
            }
        }
        val jvmMain by getting
        val jvmTest by getting {
            dependencies {
                implementation(kotlin("test-junit"))
            }
        }
        val jsMain by getting
        val jsTest by getting {
            dependencies {
                implementation(kotlin("test-js"))
            }
        }
        val nativeMain by getting
        val nativeTest by getting
    }
}
e

edrd

09/26/2020, 2:05 AM
Shouldn't the dependency be added to the
commonMain
source set? https://kotlinlang.org/docs/reference/mpp-add-dependencies.html
Another option: https://kotlinlang.org/docs/reference/using-gradle.html#set-dependencies-at-the-top-level
g

Gabriel Santos

09/26/2020, 12:54 PM
Yes, this works! Thank you.
👍 1
View count: 1