https://kotlinlang.org logo
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
  • b

    bod

    02/14/2019, 12:44 PM
    Hello, World! I have a pattern that happens a lot in our codebase: enums with a String key, and we need to get the enum value from the key, or a special “unknown” value. So what we do currently is something like:
    enum class MyEnum(val key: String) {
        FOO("foo"),
        BAR("bar"),
        UNKNOWN("unknown");
    
        companion object {
            fun getByKey(key: String?): MyEnum {
                return MyEnum.values().firstOrNull { it.key == key } ?: MyEnum.UNKNOWN
            }
        }
    }
    I’m looking for a way to not repeat this companion object for all our enums. Possibly a combination of an interface and a generic extension function? Any idea? 🙂 [sorry I already posted this before to an unrelated channel by mistake]
    o
    m
    • 3
    • 4
  • t

    thana

    02/14/2019, 1:10 PM
    i changed the jdk from 12 to 11. trying to run
    ./gradlew build
    i now always get this error
    > Task :authmock:compileKotlin FAILED
    e: No class roots are found in the JDK path: /usr/lib/jvm/java-12-openjdk-amd64
    any idea what to do?
    • 1
    • 1
  • m

    Marcin Wisniowski

    02/14/2019, 3:19 PM
    java.lang.Long.parseLong()
    Why isn't this available in the Kotlin
    Long
    ?
    t
    d
    j
    • 4
    • 9
  • l

    LeoColman

    02/14/2019, 3:34 PM
    I ran into an issue sooner today when I serialized a data class that contained an enum, and the hashcode was always different
    i
    • 2
    • 10
  • l

    LeoColman

    02/14/2019, 3:34 PM
    What made me think that
    Enum.foo
    would sometimes be differente from
    Enum.foo
    , and that's impossible?
    c
    d
    • 3
    • 4
  • e

    elect

    02/14/2019, 5:46 PM
    is there a way other than going down with annotation and code generation?
    d
    • 2
    • 7
  • d

    DaveQ

    02/14/2019, 5:53 PM
    Has anyone seen the "mock-maker-inline" feature suddenly stop working? Was able to mock final classes yesterday but then this morning it just... stopped. Using Mockito 2 (2.17.0) and IntelliJ.
    s
    d
    • 3
    • 7
  • s

    Scott Dillender

    02/14/2019, 6:17 PM
    Is there a relatively simple way to convert a channel to a sequence? At present using a broadcast channel to send events through two separate coroutines for processing. I'm trying:
    sequence {
                        yield(channelSubscription.receive())
                    }
    but that errors out with:
    Restricted suspending functions can only invoke member or extension suspending functions on their restricted coroutine scope
    d
    • 2
    • 7
  • j

    james.ayvaz

    02/14/2019, 7:55 PM
    Is there a standard way to read kotlin dsl from a file and construct the objects from it. For Example I want to read a text file containing kotlinx.html code.
    d
    • 2
    • 1
  • j

    jeremy

    02/15/2019, 4:12 AM
    Might need to add kotlin-reflect for extensions?
    s
    • 2
    • 1
  • s

    serebit

    02/15/2019, 4:13 AM
    should use threads, guys
    🇳🇴 1
    ➕ 1
    :thread-please: 1
    j
    • 2
    • 1
  • s

    sitepodmatt

    02/15/2019, 4:22 AM
    test_kt.kt
    👍 1
    j
    • 2
    • 1
  • e

    elect

    02/15/2019, 9:19 AM
    if I know that this Enum extends also a specific interface, is there a way to express it in its type?
    val values: Array<out Enum<*>> = Enum::class.java.enumConstants
    d
    k
    • 3
    • 5
  • a

    aerialist

    02/15/2019, 11:56 AM
    Hi All, Could you say which version of Gradle is minimal required to build my Kotlin v.1.3.21 project?
    d
    • 2
    • 8
  • e

    egorand

    02/15/2019, 3:55 PM
    Got a bug report on KotlinPoet regarding the following scenario:
    enum class RenderPassCreate(override val value: Int) {
        companion object
    }
    This is the code we currently generate, and it will not compile, with the error being
    Expecting ';' after the last enum entry or '}' to close enum class body
    . The compiler expects the following:
    enum class RenderPassCreate(override val value: Int) {
        ;
        companion object
    }
    which in my opinion looks ugly. I wonder if there’s a hard technical limitation behind this, and whether the compiler could handle this better? Tried searching YouTrack and it doesn’t look like it’s been filed
    r
    d
    • 3
    • 7
  • s

    streetsofboston

    02/15/2019, 5:56 PM
    Kotlin has more constructs that are expressions than Java has (e.g.
    if
    ,
    when
    ,
    try
    expressions in Kotlin, but not in Java). What was the reason that the assignment operator
    =
    is not an expression?
    i
    g
    k
    • 4
    • 5
  • d

    Dominaezzz

    02/15/2019, 7:04 PM
    What's the best I can get to an enum entry alias?
    e
    d
    • 3
    • 16
  • s

    Seri

    02/15/2019, 8:18 PM
    Is there a better way to write
    list.filter { ... }.isNotEmpty()
    ? IDEA is telling me that the calls could be simplified, but I’m not seeing how
    f
    • 2
    • 3
  • j

    James

    02/15/2019, 9:17 PM
    does this look like a bug? I think the the debugger has issues with automatic type inference because this only fails without the cast, even though the linter tells me i shouldn't need the cast. I noticed something similar at runtime in some other code i wrote where the type is erased, and failed when it shouldn't have
    s
    a
    • 3
    • 2
  • b

    basher

    02/16/2019, 12:59 AM
    Are coroutines guaranteed to run to completion (i.e. can they be interrupted) on a given thread as long as they don't suspend (i.e. call a suspending function)?
    s
    • 2
    • 2
  • e

    elect

    02/16/2019, 7:30 AM
    is there a way to add an extension function to a java class?
    class Whatever // Java
    // kotlin
    fun Whatever.String.extend() = 3
    fun a(block: Whatever.()->Unit) {
       Whatever().block()
    }
    // in order to do somewhere in code
        a {
            "hello".extend()
        }
    r
    • 2
    • 4
  • g

    GarouDan

    02/16/2019, 1:30 PM
    Hi, does someone know if we have a docker image so we can build ios applications with kotlin? Or an example of a
    Dockerfile
    ?
    a
    s
    • 3
    • 9
  • g

    GarouDan

    02/16/2019, 4:26 PM
    I’m trying to compile a kotlin project with jdk11 but I’m receiving this error:
    > Task :common:linkTestDebugExecutableNativeAndroidArm32 FAILED
    /root/.konan/dependencies/clang-llvm-6.0.1-linux-x86-64/bin/llvm-lto: error while loading shared libraries: libtinfo.so.5: cannot open shared object file: No such file or directory
    error: compilation failed: The /root/.konan/dependencies/clang-llvm-6.0.1-linux-x86-64/bin/llvm-lto command returned non-zero exit code: 127.
    Does someone knows how to fix this? The library
    libtinfo.so.5
    is missing. It looks like this could be related with
    ncurses
    . Some people suggested to install this package
    yum install ncurses-compat-libs
    but I don’t know which package I should install when using debian.
    d
    • 2
    • 9
  • a

    amanda.hinchman-dominguez

    02/17/2019, 12:46 AM
    Does anyone know why you're unable to use multiple varargs as parameters in a constructor in Kotlin and if there might be a possible workaround?
    r
    s
    • 3
    • 6
  • a

    amanda.hinchman-dominguez

    02/17/2019, 1:11 AM
    Doesn't
    Module... modules
    mean you can pass in a vararg in to the function call?
    s
    • 2
    • 2
  • a

    amanda.hinchman-dominguez

    02/17/2019, 1:16 AM
    @snowe honestly, this issue baffles me then
    s
    • 2
    • 9
  • a

    amanda.hinchman-dominguez

    02/17/2019, 1:20 AM
    @snowe nice!!! Thanks for help with the splat. This is what the result looks like with the TornadoFX workaround:
    s
    • 2
    • 2
  • r

    Rohan Maity

    02/17/2019, 9:18 AM
    Hello ! Kotlin language is cool . And I like Kotlin language can be used in multiple platforms (Kotlin-JS, Kotlin/Native) and beautiful Kotlin Coroutines . But I am supposed to give the intro to Kotlin language , highlight kotlins feature every week . Any ideas how can I make more people engaging in Kotlin? Still many people I find people using Kotlin are Java converts and Android developer . But I want to highlight other Kotlin features and make students know use Kotlin language . Any guidance can I get ? Any help would be appreciated . Thank you
    e
    t
    +2
    • 5
    • 79
  • c

    camdenorrb

    02/17/2019, 12:14 PM
    Any ideas for why this weird output is happening?
    c
    k
    • 3
    • 5
  • f

    frellan

    02/17/2019, 9:52 PM
    Lets say
    Foo
    is a
    Stream<Whatever>
    , I want to map and convert it to a Sequence, is there any difference at all between these?
    foo
    .asSequence()
    .map { it.doStuff() }
    or
    foo
    .map { it.doStuff() }
    .asSequence()
    r
    d
    • 3
    • 6
Powered by Linen
Title
f

frellan

02/17/2019, 9:52 PM
Lets say
Foo
is a
Stream<Whatever>
, I want to map and convert it to a Sequence, is there any difference at all between these?
foo
.asSequence()
.map { it.doStuff() }
or
foo
.map { it.doStuff() }
.asSequence()
r

Ruckus

02/17/2019, 10:17 PM
The first does the
map
operation on the stream, the second does it on the sequence.
The end result should be the same, but the first uses Java APIs and the second uses Kotlin APIs.
f

frellan

02/17/2019, 10:37 PM
Yeah, I’m thinking about performance
d

Dico

02/17/2019, 11:08 PM
The performance would expectably be very similar. Do a test if you want.
f

frellan

02/17/2019, 11:21 PM
Yeah I guess. I was mainly interested in knowing if there was some practice for this, so you don’t break laziness or utilize it on the best way or whatever but I guess
Sequence
and
Stream
should be pretty interchangable on that
d

Dico

02/18/2019, 7:07 AM
When you invoke
asSequence()
, that's not even a terminal operation
View count: 2