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

    v79

    11/05/2018, 8:11 AM
    What has happened to the Kotlin Standard Library JRE since 1.3 came out?
    kotlin-stdlib-jre8
    is only verison 1.2.71 in maven and marked as deprecated.
    e
    • 2
    • 2
  • n

    nitrog42

    11/05/2018, 10:44 AM
    hm I see that cache redirector looks like a repository introduced by gradle-intellij-plugin, so the issue probably come from it
    m
    • 2
    • 6
  • m

    mersan

    11/05/2018, 10:55 AM
    trying this code
    runBlocking {
    
          val timer = measureTimeMillis { delay(1000) }
          println("Delay Measure: $timer")
    
          val timer2 = measureTimeMillis { Thread.sleep(1000) }
          println("Thread Sleep Measure: $timer2")
    
        }
    but the result was unexpected for me:
    Delay Measure: 1064
    Thread Sleep Measure: 1002
    Is it something I should expect the
    delay
    in coroutine takes more time than the
    Thread.sleep
    ?
    g
    • 2
    • 3
  • j

    jcechace

    11/05/2018, 12:41 PM
    Any idea how to write this piece of code nicer?
    override fun checkServerTrusted(chain: Array<out X509Certificate>?, authType: String?) {
            try {
                customTm?.checkServerTrusted(chain, authType) ?: defaultTm.checkServerTrusted(chain, authType)
            } catch (e : CertificateException) {
                defaultTm.checkServerTrusted(chain, authType)
            }
        }
    m
    c
    • 3
    • 4
  • a

    arve

    11/05/2018, 1:33 PM
    val input: List<List<Double>> = 
     [[1, 2, 3 (....)],
      [4, 5, 6, (...)],
      [7, 8, 9, (...)]] 
    val expected= [12, 15, 18, (...)]
    Trying to find an elegant way to sum elements of a list of list of numbers by index (i.e. "downwards")🤔
    c
    • 2
    • 1
  • d

    diesieben07

    11/05/2018, 1:34 PM
    input.map { it.sum() }
    ?
    🇳🇴 1
    a
    m
    +2
    • 5
    • 14
  • d

    DJ Mitchell

    11/05/2018, 4:01 PM
    Hi 👋 I'm coming from the Swift world and there are a set of protocols over there that called
    ExpressibleByXXXXLiteral
    , so you can create a type and if you pass the correct type of literal as an argument the compiler will automatically lift that literal into the correct type. For instance one nice thing in Kotlin would be to be able to express an
    inline class
    as a literal without having to explicitly initialize a type at the callsite:
    inline class UserID(val value: Int) {}
    
    data class User(val userID: UserID) {}
    
    // would love to be able to do this
    val user = User(5)
    
    // instead i have to do this
    val user = User(UserID(5))
    r
    a
    c
    • 4
    • 7
  • g

    gsala

    11/05/2018, 4:05 PM
    doesn't that miss the point of the inline class though? If
    User
    requires a
    UserID
    to be constructed, it shouldn't be allowed to be constructed with any
    Int
    :thread-please: 2
    d
    m
    +3
    • 6
    • 39
  • j

    John Dengis

    11/05/2018, 6:03 PM
    Hey, I was using Kotlin with a couple of Java libraries and encounter an internal compiler error when working with inheritance and a few different types of annotations. What is the process to go through for filing compiler bug reports? I went to the Kotlin YouTrack site, but couldn't find where to submit a new issue.
    e
    • 2
    • 2
  • p

    pavel

    11/06/2018, 12:07 AM
    So I have a piece of code that looks like this:
    val foo = listOf("foo", "bar", null, "")
        val bar = foo.filter { !it.isNullOrEmpty() }
    the compiler is arguing that
    bar
    is
    List<String?>
    while my position is that it should be
    List<String>
    . Am I expecting too much from contracts? And is there a better way to write this?
    s
    l
    +2
    • 5
    • 14
  • c

    christophsturm

    11/06/2018, 9:24 AM
    is there a kotlin lib that will fill data objects with random data for testing? something like https://github.com/topicusoverheid/java-factory-bot
    m
    d
    • 3
    • 3
  • e

    elect

    11/06/2018, 10:16 AM
    I can see (by the `println`s in console) that my
    lazy
    is actually being executed twice: https://github.com/kotlin-graphics/uno-sdk/blob/master/src/main/kotlin/uno/awt/JawtDemo.kt#L79-L84
    j
    • 2
    • 3
  • e

    elect

    11/06/2018, 10:17 AM
    how is that possible? Ps: calling it from java
    s
    • 2
    • 4
  • a

    APXEOLOG

    11/06/2018, 1:38 PM
    Guys what library do you use for json object mapping? I'm using
    jackson-module-kotlin
    for now, but i face some issues there with kotlin support. Maybe there are some other simple to use and easily customisable solutions
    a
    e
    +3
    • 6
    • 6
  • v

    vibin

    11/06/2018, 2:46 PM
    v
    d
    +4
    • 7
    • 17
  • p

    pawel.urban

    11/06/2018, 3:45 PM
    Is there any neat way of doing
    private val _title = BehaviorRelay.create<String>()
        val title: Observable<String> = _title
    without the backing property?
    :thread-please: 1
    h
    r
    • 3
    • 4
  • d

    dave08

    11/06/2018, 4:15 PM
    Say I have a
    val someSet: Set<String>? = setOf("this", "that", "this=3")
    and I'd like to extract the 3 as an
    Int
    , is this the most ideomatic/efficient way to do it?
    someSet?.firstOrNull { it.startsWith("this=") }
    					?.substringAfter("this=")
    					?.toInt() ?: 0
    d
    d
    • 3
    • 4
  • c

    coder82

    11/06/2018, 4:35 PM
    can_I_use_a_wildcard_for_websocket_routes_.js
    m
    • 2
    • 2
  • m

    miha-x64

    11/06/2018, 5:31 PM
    Are there any ways to achieve exhaustiveness, but enums or sealed classes? I have a bunch of objects and want to provide each of them with some data. (Certainly, I've got DTO schema and want to add platform-specific (SQL-specific, JSON-specific, etc) metadata)
    s
    • 2
    • 2
  • b

    breun

    11/06/2018, 9:04 PM
    The context for me would be a server application serving API calls.
    k
    • 2
    • 1
  • s

    stkent

    11/06/2018, 9:31 PM
    I'm trying to build a Kotlin version of the lazy prime number generator based on the Sieve of Eratosthenes from this Haskell video (10m55s):

    https://www.youtube.com/watch?v=bnRNiE_OVWA&amp;t=10m55s▾

    I ended up here:
    fun sieve(remainderSequence: Sequence<Int> = generateSequence(2) { it + 1 }): Sequence<Int> {
        val newPrime = remainderSequence.first()
        val newRemainderSequence = remainderSequence.filterNot { it % newPrime == 0 }
    
        return sequence {
            yield(newPrime)
        }.plus(sieve(newRemainderSequence))
    }
    which I thought would remain lazy, but it appears not to. What am I missing?
    e
    n
    +2
    • 5
    • 33
  • t

    tateisu

    11/07/2018, 1:54 AM
    Auto format does bit strange indent. Is there settings to fix it?
    k
    g
    • 3
    • 13
  • z

    Zaidi

    11/07/2018, 9:56 AM
    if is there any one who can help me to use IntentServices in dagger2 ?
    :stackoverflow: 2
    g
    • 2
    • 3
  • d

    deviant

    11/07/2018, 10:54 AM
    what is more efficient way to check if property instantiated?
    ::logger.isInitialized
    or
    logger==null
    i mean should i avoid
    isInitialized
    lateinit feature due to reflection magic?
    d
    • 2
    • 1
  • m

    mikehearn

    11/07/2018, 12:18 PM
    just wondering if there's an overload somewhere for it
    h
    • 2
    • 1
  • c

    CamilleBC

    11/07/2018, 12:55 PM
    Hey guys ! Is there an equivalent way in Kotlin to download a file from a URL without buffering into mermory? Like with Java.NIO?
    c
    g
    • 3
    • 5
  • c

    CamilleBC

    11/07/2018, 1:05 PM
    Thanks! I'll first try using the java.nio classes. I don't why I didn't just try that 😄
    d
    • 2
    • 1
  • k

    karelpeeters

    11/07/2018, 2:51 PM
    val str = "hey"
    
    when (val line = str) {
        "abc" -> println("abc")
        line.startsWith("h") -> println("starts with h")
    }
    Any reason this doesn't work? It says
    Incompatible type: Boolean and String
    on the
    .startsWith
    part.
    m
    s
    +3
    • 6
    • 14
  • k

    karelpeeters

    11/07/2018, 5:11 PM
    Is there currently a way to define sealed class inheritors in multiple files? They're getting a bit too big for a single file.
    s
    r
    b
    • 4
    • 8
  • b

    beepdog

    11/07/2018, 7:15 PM
    object RTMMessages {
        sealed class Message(val id: Long, val type: String, val channel: String){
            class Typing() : Message(id, "typing", channel)
        }
    }
    d
    • 2
    • 9
Powered by Linen
Title
b

beepdog

11/07/2018, 7:15 PM
object RTMMessages {
    sealed class Message(val id: Long, val type: String, val channel: String){
        class Typing() : Message(id, "typing", channel)
    }
}
d

dalexander

11/07/2018, 7:18 PM
I’m not sure what you’re trying to do with this code, could you elaborate a bit and I’ll see if I can suggest something?
👆 1
b

beepdog

11/07/2018, 7:22 PM
I'm trying to create a message hierarchy for the Slack RTM payloads
so there will be several different kinds of
Message
and it'd be nice to have the compiler cover the "oh you forgot to include this type" stuff
https://kotlinlang.slack.com/archives/C0922A726/p1541618557099700
this seems to be the way to do it
d

dalexander

11/07/2018, 7:27 PM
Hmmm, okay. I would probably just have used sealed classes. If you’re forced to construct the base class it makes it hard to forget something.
b

beepdog

11/07/2018, 8:07 PM
am I not using sealed classes?
d

dalexander

11/07/2018, 8:12 PM
Oh, that’s my mistake, I’m used to sealed classes needing to have their subclasses nested.
View count: 2