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

    LastExceed

    08/25/2019, 9:13 AM
    why isn't bit shifting implemented for
    Short
    and
    Byte
    ?
    g
    • 2
    • 1
  • g

    gumil

    08/25/2019, 10:54 AM
    What is the recommended JDK when using Kotlin? Does the JDK version matter when using Kotlin?
    m
    • 2
    • 2
  • s

    Slackbot

    08/25/2019, 2:36 PM
    This message was deleted.
    m
    • 2
    • 1
  • s

    synhershko

    08/25/2019, 9:09 PM
    Hey all! I'm looking for some help with BroadcastChannel - I seem to be missing something as my code runs forever and subscribers to the BroadcastChannel never receive any message. Is there a good example I can follow somewhere? or someone I can ask?
    s
    • 2
    • 2
  • a

    Alexander Shustanov

    08/26/2019, 6:27 AM
    Hi! I am developing a plugin for Idea. The plugin provides some code analysis, generation, custom editors, inspections, references, etc. I started to support these functionality for Kotlin recently. Is there any class in Idea Kotlin plugin to replace java classes fqn to kotlin classes fqn(java.lang.String -> kotlin.String)?
    • 1
    • 1
  • p

    Paul Woitaschek

    08/26/2019, 8:10 AM
    Can I find out what kapt was actually doing? In my build scan I have 1:12 minutes of
    kaptGenerateStubsDevKotlin
    even though I only have
    kapAndroidTest
    ,
    kaptRelease
    and
    kaptDebug
    in my gradle file.
    🤔 2
    w
    d
    +4
    • 7
    • 53
  • e

    elect

    08/26/2019, 12:57 PM
    is there a possibility to use contracts for assuring the compiler a
    val
    interface field will be initialized exactly only once?
    m
    • 2
    • 10
  • s

    Sam Schilling

    08/26/2019, 4:13 PM
    Is there any guide on how to use the Native Debug for IntelliJ plugin? I want to debug native code but simply installing the plugin and setting breakpoints doesn’t seem to work. I am using the latest version of Ultimate (free trial)
    g
    • 2
    • 6
  • e

    elect

    08/26/2019, 4:55 PM
    Trying to have enums backed by an
    IntBuffer
    , I'm writing an extension function for an Enum, where its companion object extends a specific interface. But if I cast, the compiler says the cast can never succeed.. why?
    fun <E> Enum<E>.bind() where E : Enum<E>, E : A = (Enum.Companion as B).buffers[ordinal].bind() // this cast can never succeed
    s
    j
    +2
    • 5
    • 26
  • s

    Shashank

    08/26/2019, 5:22 PM
    I have the code
    runBlocking {
            val one = async { function1() }
            val two = async { function2() }
            one.await()
        }
    Even though I just call
    one.await()
    I see that function 2 is executed as well? Can anyone explain why is it so? I was under the impression that calling
    await()
    is what triggers the execution.
    s
    s
    d
    • 4
    • 23
  • m

    molikuner

    08/26/2019, 5:32 PM
    Is there a way to force an inhering class to have a companion object with a function?
    🇳🇴 1
    s
    d
    • 3
    • 4
  • v

    Vishal Rana

    08/26/2019, 6:00 PM
    javac
    compiles hello world program in 500ms, is there a reason why does
    kotlinc
    takes 3 s? Is there any way I can improve this? I heard about kotlinc daemon but could not find any documents to get started.
    g
    g
    • 3
    • 19
  • i

    Ifvwm

    08/27/2019, 3:56 AM
    type infrence failed: Cannot infer type parameter A in fun <A,B,C> either... https://paste.ubuntu.com/p/XFN5NbWnZB/
    k
    k
    m
    • 4
    • 6
  • s

    Saiedmomen

    08/27/2019, 5:15 AM
    Is there a way to pass function with optional argument like
    fun fetchData(page=0) {...}
    to a function that expects a function with no argument like?
    fun runRequest(block: ()->Unit)
    k
    b
    • 3
    • 5
  • p

    Paul Woitaschek

    08/27/2019, 6:56 AM
    Im often in the situation that I have an enum class and that I want to have a value for each enum member. For example
    enum class BaseNutrient
    ->
    Map<BaseNutrient, Double>
    . Is there a more elegant way than using
    Basenutrient.values().associate { baseNutrient -> baseNutrient to 0.0 }
    As I need that so frequently it feels like I’m overseeing sth in the stdlib
    p
    a
    d
    • 4
    • 6
  • e

    elect

    08/27/2019, 9:28 AM
    an inline class of an inline class is still properly inlined?
    d
    d
    k
    • 4
    • 5
  • g

    goku

    08/27/2019, 1:32 PM
    I have seen posts about
    0.0 == -0.0
    but I wasn’t expecting to see that in a multiplication 🤔
    m
    r
    +3
    • 6
    • 21
  • r

    ribesg

    08/27/2019, 2:35 PM
    Why can’t I pass a value of type
    Map<String, String?>
    for a parameter requiring type
    Map<Any?, *>
    ?
    b
    t
    +2
    • 5
    • 19
  • f

    Fin

    08/28/2019, 6:36 AM
    Is there any easier way in Kotlin to achieve that mapping to state variables without repeating myself over and over again? Can I make my State attributes somehow directly accessible in main Class?
    Untitled
    s
    a
    b
    • 4
    • 7
  • m

    Michal Klimczak

    08/28/2019, 6:56 AM
    Hello, I need to create a list of anonymous function literals with receivers. What I got is
    private val fragmentInjectors = listOf<Pair<Class<out Fragment>, Fragment.() -> Unit>>(
                MainControlFragment::class.java to fun Fragment.(){ 
                    (this as MainControlFragment).viewModelFactory = mockViewModelFactory
                }
        )
    but ideally I would like something like
    private val fragmentInjectors = listOf<Pair<Class<out Fragment>, Fragment.() -> Unit>>(
                MainControlFragment::class.java to fun MainControlFragment.(){ 
                   this.viewModelFactory = mockViewModelFactory
                }
        )
    to avoid casting. But unfortunately compiler complains about
    type inference failed, expected type mismatch
    because of MainControlFragment and Fragment being different types. Anyone knows the right syntax?
    m
    w
    • 3
    • 8
  • t

    thana

    08/28/2019, 3:11 PM
    awesome. i have a kotlin file with 359 lines in total, let intellij show me the bytecode. Trying to decompile the byte code intellij hardly survives and after minutes of waiting it warns me that it can only 2.56MB of the total of 155.44MB. is that a normal thing?
    👍 1
    l
    k
    • 3
    • 9
  • l

    Luis Munoz

    08/28/2019, 3:22 PM
    I have a field that needs to be initialized after the object is created and then never modified, is there way to make it immutable so that it can be read concurrently after initialized
    b
    d
    • 3
    • 5
  • t

    Travis Griggs

    08/28/2019, 5:21 PM
    I have a variety of base types that I add extensions too (e.g. a foobar property), and I’d like to fetch foobar from a heterogenous collection of Any’s when/if they support it, otherwise do a default/fallback thing
    s
    k
    +3
    • 6
    • 19
  • s

    Sam Garfinkel

    08/28/2019, 5:25 PM
    What's the correct way to take an inline reified
    Collection<T>
    ? Use case is a property delegate where
    getValue
    returns
    Collection<T>
    when the type of the
    val
    is
    Collection<T>
    . I.e.
    val foo: Collection<String> by bar
    .
    s
    k
    • 3
    • 3
  • c

    corneil

    08/28/2019, 7:05 PM
    I'm not sure where to ask this: Does anyone know if
    contract
    will be able to ensure that if you do
    precondition(someThing != null) { "Something is required" }
    that
    someThing
    be detected as not null afterwards? Is this in the works?
    d
    • 2
    • 14
  • m

    Marian Schubert

    08/28/2019, 7:51 PM
    interface Foo<T> { fun bar(x: Any): Boolean { ... } }
    - is there some way to return true from bar if x is instance of T?
    s
    d
    • 3
    • 9
  • e

    edwinRNDR

    08/28/2019, 8:14 PM
    Is this a known gotcha?: https://try.kotlinlang.org/#/UserProjects/gtd3usu4s8thgaq0dllbptk1ho/199jpkdpd1at7m7rve3v1hrl4v
    s
    • 2
    • 4
  • s

    Shan

    08/28/2019, 10:59 PM
    Anyone know at what point in this process the Type of
    ResponseResult
    is getting erased and how I can avoid it?
    Type_Erasure
    d
    • 2
    • 2
  • m

    Miguel Vargas

    08/29/2019, 1:04 AM
    As I'm trying to wrap my head around all the coroutine concepts one thing that is tripping me up are
    suspend
    functions. The keyword is not very well documented but it does say that they can only be used from a coroutine. But then I ran into sequence's
    yield()
    which is a suspend function that it is called from a SequenceScope which is not a coroutine scope. As far as I know Sequences have been in Kotlin 1.0 so it precedes coroutines? I guess I'm trying to get a more basic understanding of suspend functions.
    c
    • 2
    • 1
  • b

    bjartek

    08/29/2019, 7:24 AM
    I am looking for more information on how to host your own version of try.kotlinlang.org backend. We do not need the WebIde, only the serverside component since we plan to use it the same way the use here https://jetbrains.github.io/kotlin-playground/examples/. The only real modification we want to do is add a single library that contains a DSL.
    c
    r
    • 3
    • 5
Powered by Linen
Title
b

bjartek

08/29/2019, 7:24 AM
I am looking for more information on how to host your own version of try.kotlinlang.org backend. We do not need the WebIde, only the serverside component since we plan to use it the same way the use here https://jetbrains.github.io/kotlin-playground/examples/. The only real modification we want to do is add a single library that contains a DSL.
c

Casey Brooks

08/29/2019, 1:49 PM
Perhaps look into #scripting embedded in a microservice, I believe there's a JSR-223 ScriptEngine library available
r

Richard Green

08/29/2019, 3:51 PM
The server side component is available on github somewhere I believe. I did the same thing about 18 months ago. It was somewhat problematic at the time (I had to remove all of the security manager stuff for example - but it was for internal use only) but I did manage to get it to work. I also recall they were going to improve this feature but I haven't kept track if they have @bjartek
https://github.com/JetBrains/kotlin-web-demo
https://github.com/JetBrains/kotlin-web-demo#how-to-add-your-dependencies-to-kotlin-compiler-books
b

bjartek

08/29/2019, 3:53 PM
Thanks. Will look into it
View count: 3