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

    epabst

    10/22/2019, 3:51 PM
    This was a pretty neat video about the top languages and how they became popular.

    https://youtu.be/QyJZzq0v7Z4▾

    s
    l
    +2
    5 replies · 5 participants
  • k

    KindRoacher

    10/22/2019, 6:20 PM
    Is there any reason why Kotlin chooses Double as default type for decimals over Float?
    c
    t
    +2
    5 replies · 5 participants
  • t

    tseisel

    10/22/2019, 6:45 PM
    Why do I need to cast the result of the
    map
    operation in the following sample :
    sealed class Request<T> {
        object Pending : Request<Nothing>()
        class Success<T>(val result: T) : Request<T>()
        class Failure(val error: Throwable) : Request<Nothing>()
    }
    
    val sourceFlow: Flow<Foo> = getFooFlow()
    sourceFlow.map { Request.Success(it) as Request<Foo> }
        .onStart { emit(Request.Pending) }
        .catch { emit(Request.Failure(it) }
        .onEach { ... }
        .launchIn(scope)
    Will this kind of issue be fixed by the new Kotlin inference ? Or is there a workaround (other than creating a typed temporary variable) ?
    s
    4 replies · 2 participants
  • s

    Slackbot

    10/22/2019, 8:49 PM
    This message was deleted.
    b
    1 reply · 2 participants
  • k

    KyooSik Lee

    10/23/2019, 4:55 AM
    I have a data class foo
    kotlin
    data class Foo(
        val a: Int,
        val b: String,
        val c: Int
        val d: Int
    ) {}
    And I have another data class partialFoo, where I have partial fields of foo
    kotlin
    data class PartialFoo(
        val a: Int,
        val b: String
    ) {}
    Is there any way that I can copy the fields of class instance of
    Foo
    to class instance of
    PartialFoo
    ?
    k
    b
    +1
    19 replies · 4 participants
  • t

    Travis Griggs

    10/23/2019, 5:36 AM
    kotlin experimental unsigned types can’t be shifted? (at least, not UShort?)
    r
    2 replies · 2 participants
  • t

    Travis Griggs

    10/23/2019, 5:37 AM
    for example, I have a byte array, I want to grab bytes.slice(3 until 5) and get a UShort from them
    r
    1 reply · 2 participants
  • j

    jmillner_

    10/23/2019, 8:23 AM
    Those annotations won't come from the plugin I don't think, they should come from a dependency defined in your build gradle -> dependency block
    r
    1 reply · 2 participants
  • j

    Jacky Android

    10/23/2019, 8:57 AM
    Why does the kotlin github repo README file not translate to other languages?
    ❓ 2
    🙃 3
    s
    l
    3 replies · 3 participants
  • s

    Steve

    10/23/2019, 5:53 PM
    Is there a channel for discussing the Android Dev Summit stuff?
    p
    g
    2 replies · 3 participants
  • t

    Tmpod

    10/23/2019, 6:10 PM
    howdy! I was wondering if KMongo has coro support for GridFS
    e
    2 replies · 2 participants
  • k

    Krotick

    10/24/2019, 5:36 AM
    I am using DynamDBMapper annotations on a data class (AWS Java SDK). The mapper uses a default Java constructor pattern when deserializing an object, assigning properties through setters after object instantiation. Is there anything I can do on my end to retain read-only
    val
    attributes in the class constructor? I had to change everything to
    var
    and I hate mutability ...
    k
    2 replies · 2 participants
  • l

    libiez

    10/24/2019, 12:20 PM
    sorry wrong window
    m
    m
    +1
    3 replies · 4 participants
  • m

    Maxim Kizub

    10/24/2019, 12:33 PM
    Why can't we create generic wrapper classes, like
    class Wrapper<T> (val value: T) : T by value
    ?
    d
    m
    +1
    14 replies · 4 participants
  • a

    Ashutosh Panda

    10/24/2019, 2:10 PM
    import kotlin.random.Random
    
    val x= Random().nextInt(from :1,until :7)
            println(x)
    why is this code showing
    incomplete code
    r
    1 reply · 2 participants
  • j

    Joan Colmenero

    10/24/2019, 6:11 PM
    I've found a way to keep using
    ResultWrapper<out T>
    but I'm curious now how to implement
    Either
    on the execute method. I found a way like
    data class Success<out T : Any>(val value: T) : ResultWrapper<T>()
    k
    15 replies · 2 participants
  • t

    Travis Griggs

    10/24/2019, 9:04 PM
    UInt… is it 32 bits? Or is it “it depends” similar question for ULong 64 or “guess and see”
    r
    1 reply · 2 participants
  • d

    David Glasser

    10/24/2019, 10:30 PM
    does kotlin (jvm) have any kind of weak identity map, or an equivalent feature (ie, to let my code effectively add a property to an arbitrary object)? I know Java has WeakHashMap but I want the map to be based on identity, not hashCode.
    d
    n
    +3
    8 replies · 6 participants
  • m

    mhamade

    10/25/2019, 7:03 AM
    Is there a difference between it and this in kotlin? If so, why do different scoping functions use one but not the other?
    g
    3 replies · 2 participants
  • c

    czuckie

    10/25/2019, 10:10 AM
    hey guys, scratching my head over
    @JvmOverloads
    on a data class constructor- it doesn’t seem that every permutation of the constructor is created to match default parameters
    g
    k
    12 replies · 3 participants
  • m

    marschwar

    10/25/2019, 1:02 PM
    We are suddenly experiencing a version problem. After emptying the gradle cache the build fails without changing anything else.
    > Could not resolve all files for configuration ':api:testCompileClasspath'.
       > Could not find org.jetbrains.kotlin:kotlin-stdlib-common:1.3.60-eap-76.
         Required by:
             project :api > org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.2-1.3.60-eap-76
       > Could not find org.jetbrains.kotlin:kotlin-stdlib-common:1.3.60-eap-76.
         Required by:
             project :api > org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.3.50 > org.jetbrains.kotlin:kotlin-stdlib:1.3.50
             project :api > org.jetbrains.kotlin:kotlin-test:1.3.50 > org.jetbrains.kotlin:kotlin-test-common:1.3.50
             project :api > org.jetbrains.kotlin:kotlin-test-junit5:1.3.50 > org.jetbrains.kotlin:kotlin-test-annotations-common:1.3.50
    This is in the gradle file.
    plugins {
        id 'org.springframework.boot' version '2.1.8.RELEASE'
        id 'org.jetbrains.kotlin.jvm' version '1.3.50'
        id "org.jetbrains.kotlin.plugin.spring" version "1.3.50"
    }
    
    allprojects {
    
        apply plugin: 'kotlin'
        apply plugin: 'io.spring.dependency-management'
        apply plugin: 'kotlin-spring'
    
        repositories {
            mavenCentral()
            jcenter()
        }
    }
    Is anyone else experiencing this? Any suggestions?
    s
    2 replies · 2 participants
  • t

    Travis Griggs

    10/25/2019, 3:07 PM
    I’m confused by something. HashMap has a filterKeys (among others) method. But they’re defined as Map interface things. It seems I then have to cast the result back to HashMap, e.g. this.modifyRegistry { registry -> registry.filterKeys { oid -> keepOIDs.contains(oid) } as HashMap } I don’t understand why it doesn’t know that registry is a HashMap<PlanID, Plan>. I’ve typed it that way everywhere. But without that
    as Hashmap
    I get warnings/errors. I feel like I’m missing some piece of the puzzle that it wasn’t obvious/apparent to me to put the as Hashmap there.
    g
    d
    21 replies · 3 participants
  • s

    Sujit

    10/25/2019, 8:00 PM
    So, I just realized that with
    as?
    it does not trigger the
    init {}
    method, and I'm losing some info here when doing the casting from
    Serializable
    <http://java.io|java.io>
    interface that is setup in
    init{} block
    . So, I'm wondering if there is a way to invoke the
    init {}
    when casting with
    as?
    ?
    🤔 1
    c
    b
    4 replies · 3 participants
  • p

    pavi2410

    10/25/2019, 8:36 PM
    Any news on Kotlin 1.4?
    r
    l
    2 replies · 3 participants
  • b

    Ben Madore

    10/25/2019, 9:12 PM
    gonna do an intro to kotlin presentation at my company. slideware then a coding exercise. curious if anyone has any good coding exercises they’ve found useful for something similiar. something that actually solves a real-ish problem, and is useful for highlighting a good amount of the features that makes kotlin interesting. (something a bit more complicated than the individual kotlin koans)
    n
    f
    2 replies · 3 participants
  • n

    nwh

    10/25/2019, 9:47 PM
    On the flow page, they use an event stream as an example of a flow use. Is this really a good use case? If you consider a typical event loop, it seems like it should be producing values all the time, regardless of whether or not anything is there to receive them. Isn't that more like a Channel?
    g
    6 replies · 2 participants
  • l

    liminal

    10/25/2019, 10:25 PM
    Hi all. I set out to convince my employer to start using inline classes in our android codebase while they are still experimental. Does anyone have any arguments for or against using them while they are still experimental aside from the obvious experimental status and the fact that inline classes are awesome.
    n
    g
    12 replies · 3 participants
  • e

    Ellen Spertus

    10/25/2019, 11:38 PM
    What can I pass to a Java method that expects a
    Void!
    ?
    p
    p
    +2
    12 replies · 5 participants
  • a

    Alexander

    10/26/2019, 9:20 AM
    Has anyone used Firebase in their Kotlin applications?
    ✔️ 1
    l
    g
    3 replies · 3 participants
  • m

    mbonnin

    10/26/2019, 12:30 PM
    Anyway I can make this work somehow ?
    fun <T> foo(aClass: java.lang.Class<T>): MutableList<T> {
      return mutableListOf()
    }
    
    inline fun <reified T:Any> bar(t: T): MutableList<T> {
      // fails here: expected: MutableList<T>, found: MutableList<out T>
      return foo(t::class.java) 
    }
    k
    2 replies · 2 participants
Powered by Linen
Title
m

mbonnin

10/26/2019, 12:30 PM
Anyway I can make this work somehow ?
fun <T> foo(aClass: java.lang.Class<T>): MutableList<T> {
  return mutableListOf()
}

inline fun <reified T:Any> bar(t: T): MutableList<T> {
  // fails here: expected: MutableList<T>, found: MutableList<out T>
  return foo(t::class.java) 
}
k

karelpeeters

10/26/2019, 1:06 PM
Not really, it just doesn't make sense:
t
could have a subtype of
T
, and so
t::class.java
could be a subclass of
Class<T>
and a
MutableList
is invariant. The only thing you can do is make
bar
return
MutableList<out T>
which is correct.
m

mbonnin

10/26/2019, 1:16 PM
t
could have a subtype of
T
right, thanks !
View count: 1