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

    Hans Ellegard

    10/08/2020, 2:03 PM
    I'm trying to cram out some static dispatch from a reified type, but no luck so far:
    fun foo(dummy: Int?) {}
    fun foo(dummy: String?) {}
    
    // This causes a compilation error.
    // You get 
    //   reified.kt: (8, 5): None of the following functions can be called with the arguments supplied: 
    //   public fun foo(dummy: Int?): Unit defined in root package in file reified.kt
    //   public fun foo(dummy: String?): Unit defined in root package in file reified.kt
    inline fun <reified T> bar() {
        // As the function is inlined and the type parameter reified, I'm hoping for static dispatch,
        // i.e. depending on T, one of the overloads for foo() should be chosen.
        foo(null as? T)
    }
    
    // This function has no problems compiling, static dispatch works as expected.
    fun baz() {
        foo(null as Int?)
        foo(null as String?)
    }
    Why do I get a compilation error from
    bar
    calling
    foo
    ? I guess it has something to do with Kotlin instantiating the
    bar
    function even though it's supposed to be inlined yet never called (with an actual type parameter), but I haven't found the reason yet (I read https://kotlinlang.org/spec/runtime-type-information.html#runtime-available-types but found no explanation).
    n
    • 2
    • 62
  • a

    Andrea Giuliano

    10/08/2020, 3:38 PM
    Hi guys, is there any way to get a slice of a ByteArray without copying the content in a new ByteArray? Say I have a ByteArray of 100 bytes and I just want a slice (without copying the original ByteArray) from 2 to 10 for example
    a
    z
    +3
    • 6
    • 7
  • v

    Vera van Mondfrans

    10/09/2020, 7:33 AM
    fun getDomain(obj: Any) {
      when(obj) {
        is KrsProject -> obj.someMemberFunctionOnKrsProject()
      }
    }
    Why would this work? Doesn’t the type get erased?
    ✅ 1
    r
    • 2
    • 4
  • m

    Marc Knaup

    10/09/2020, 9:06 PM
    What can I do if debugging is painfully slow? Stepping takes ages and loading data too 😕
    n
    c
    • 3
    • 6
  • b

    Big Chungus

    10/09/2020, 10:21 PM
    Dear gradle plugin authors. While working on my npm-publish plugin I've discovered how painful it is to write gradle files for functional tests efficiently. So I've written a single-file DSL for you to drop-in to you projects that puts at least some formatting/validation on gradle buildscript generation. It could be used for any kotlin file generation as well. Here's a snippet and I'm looking forward to hearing your thoughts!
    👍 1
    g
    • 2
    • 6
  • i

    itnoles

    10/09/2020, 10:35 PM
    It would nice to have Kotlinx serialization to support XML from Okio.
    v
    m
    • 3
    • 4
  • s

    Slackbot

    10/10/2020, 3:45 AM
    This message was deleted.
    m
    j
    • 3
    • 4
  • m

    mbonnin

    10/10/2020, 9:07 AM
    Can someone explain why this works?
    fun listOfArrays(): List<Array<Any>> {
      return listOf(arrayOf("1", 0))
    }
    But not this?
    fun listOfArrays(): List<Array<Any>> {
      // Type mismatch: inferred type is List<Array<out {Comparable<*> & java.io.Serializable}>> but List<Array<Any>> was expected
      return listOf(arrayOf("1", 0)).map { it }
    }
    l
    n
    i
    • 4
    • 7
  • m

    Marc Knaup

    10/10/2020, 10:13 PM
    Is there a trick to get use
    T?
    in a place where you need
    T
    ? Unfortunately there’s no
    T!
    😄 Alternatively in a function where I want a non-nullable
    T
    for
    reified T: Any?
    . Basically
    T & Any
    .
    n
    r
    l
    • 4
    • 7
  • a

    akuleshov7

    10/10/2020, 10:36 PM
    Hey guys, we have created a linter (checker + autofixer) for Kotlin with a huge number of rules. Will be great if you will support it at least with a very simple thing: star on a GitHub: https://github.com/cqfn/diKTat But if you will have a chance try it in your CI/CD :)
    r
    v
    k
    • 4
    • 30
  • r

    rkeazor

    10/12/2020, 12:43 AM
    What time zone is the 1.4 event happening?
    v
    i
    • 3
    • 5
  • l

    Law Gimenez

    10/12/2020, 2:19 PM
    How did they come up with the name Kotlin by the way?
    s
    n
    +3
    • 6
    • 10
  • h

    huehnerlady

    10/12/2020, 3:48 PM
    Is there any overview which version of kotlin supports which java version? I just know by trial and error that 1.4 now supports Java 14, but would love some overview if that exists?
    n
    m
    s
    • 4
    • 8
  • u

    user

    10/12/2020, 4:18 PM
    message has been deleted
    l
    • 1
    • 1
  • a

    addamsson

    10/12/2020, 8:16 PM
    I've noticed a while ago that in some cases I can't see the source code (only some generated/decompiled) code when I try to look at Koltin classes. For example the source of
    Channel
    looks like this when I Ctrl + Click on it:
    public interface Channel<E> : kotlinx.coroutines.channels.SendChannel<E>, kotlinx.coroutines.channels.ReceiveChannel<E> {
        public companion object Factory {
            public const final val BUFFERED: <http://kotlin.Int|kotlin.Int> /* compiled code */
    
            internal final val CHANNEL_DEFAULT_CAPACITY: <http://kotlin.Int|kotlin.Int> /* compiled code */
    
            public const final val CONFLATED: <http://kotlin.Int|kotlin.Int> /* compiled code */
    
            public const final val DEFAULT_BUFFER_PROPERTY_NAME: kotlin.String /* compiled code */
    
            internal const final val OPTIONAL_CHANNEL: <http://kotlin.Int|kotlin.Int> /* compiled code */
    
            public const final val RENDEZVOUS: <http://kotlin.Int|kotlin.Int> /* compiled code */
    
            public const final val UNLIMITED: <http://kotlin.Int|kotlin.Int> /* compiled code */
        }
    }
    What can I do to fix this and see the source (IDEA says that this file is called
    Channel.kotlin_metadata
    )?
    s
    r
    +2
    • 5
    • 87
  • a

    Akasha Peppermint

    10/13/2020, 5:26 AM
    i just noticed that Array.kt in kotlin 1.4.10 has an inline constructor but when I try to do it intellij says "Modifier is not applicable for constructor" why is this?
    k
    • 2
    • 2
  • m

    Michael de Kaste

    10/13/2020, 1:43 PM
    what am I missing?
    s
    v
    t
    • 4
    • 15
  • d

    daphillips

    10/13/2020, 3:22 PM
    I'm getting an error when trying to override a function that's implemented by delegation (context in thread)
    b
    e
    • 3
    • 12
  • w

    Wesley Acheson

    10/13/2020, 4:26 PM
    Is it possible from a variable containing a class to list the possible value if the class extends enum
    s
    g
    • 3
    • 8
  • s

    Slackbot

    10/13/2020, 5:46 PM
    This message was deleted.
    n
    s
    • 3
    • 3
  • d

    Daniel

    10/13/2020, 7:30 PM
    Hello, what is the difference between
    private val _state = MutableStateFlow<Foo>(Foo())
    val state = StateFlow<Foo> get() = _state
    and
    private val _state = MutableStateFlow<Foo>(Foo())
    val state = StateFlow<Foo> = _state
    ? Jetbrains and Google use the first form in their documentation, but isn't a
    val
    read-only regardless of whether it is specified as only having a getter or not?
    👍 1
    z
    s
    a
    • 4
    • 19
  • d

    Daniel

    10/13/2020, 8:18 PM
    The android room with a view codelab (https://codelabs.developers.google.com/codelabs/android-room-with-a-view-kotlin/#7) gives you this code to copy-paste, but doesn't explain why they use the kotlin coroutines internal function
    synchronize
    , or how to understand how it works. Can anyone help me figure out what this actually does? (I figured out it was an internal fn from the warning I got from Android Studio)
    // Annotates class to be a Room Database with a table (entity) of the Word class
    @Database(entities = arrayOf(Word::class), version = 1, exportSchema = false)
    public abstract class WordRoomDatabase : RoomDatabase() {
    
       abstract fun wordDao(): WordDao
    
       companion object {
            // Singleton prevents multiple instances of database opening at the
            // same time. 
            @Volatile
            private var INSTANCE: WordRoomDatabase? = null
    
            fun getDatabase(context: Context): WordRoomDatabase {
                val tempInstance = INSTANCE
                if (tempInstance != null) {
                    return tempInstance
                }
                synchronized(this) {
                    val instance = Room.databaseBuilder(
                            context.applicationContext,
                            WordRoomDatabase::class.java, 
                            "word_database"
                        ).build()
                    INSTANCE = instance
                    return instance
                }
            }
       }
    }
    Is all this necessary? How does this differ from the more normal way I've seen people write something to cache a return value, which doesn't use
    @Volatile
    or
    synchronized
    ? Something like
    private var _cache: WordRoomDatabase? = null
    
    fun getDatabase(context: Context): WordRoomDatabase {
        val cached = _cache // also, why is this necessary actually?
        if (cached != null) {
            return cached
        } else {
            _cache = Room.databaseBuilder(
                            context.applicationContext,
                            WordRoomDatabase::class.java, 
                            "word_database"
                        ).build()
            return cache
        }
    }
    i
    p
    • 3
    • 8
  • c

    Corey Lanier

    10/14/2020, 4:50 AM
    HELP I keep getting a reference error trying to call the data class
    copy
    m
    • 2
    • 4
  • r

    Rob Elliot

    10/14/2020, 10:33 AM
    I’m a bit confused that this compiles:
    val x: Int? = null
    val xs: Set<Int> = setOf(1, 2, 3)
    xs.contains(x) // compiles, but why?
    because the type of
    contains
    is
    public operator fun <@kotlin.internal.OnlyInputTypes T> Iterable<T>.contains(element: T): Boolean
    . Does
    @kotlin.internal.OnlyInputTypes
    mean that `T`is defined by the type of
    element
    not of the receiver? I guess that would type check, as
    Int
    is a subtype of
    Int?
    - right?
    s
    n
    i
    • 4
    • 21
  • g

    Gabriel

    10/14/2020, 2:14 PM
    A bit of a random q, does junit have something similar to https://jest-bot.github.io/jest/docs/expect.html#expectassertionsnumber it's mainly used for async code to verify that assertions are being, well, asserted
    c
    • 2
    • 1
  • s

    Slackbot

    10/14/2020, 2:54 PM
    This message was deleted.
    👍 1
    v
    o
    • 3
    • 2
  • a

    addamsson

    10/14/2020, 7:39 PM
    Do you know a good assertions library for Kotlin Multiplatform? I've been using AssertJ (https://joel-costigliola.github.io/assertj/) until now, but it only works on the JVM.
    ➕ 1
    j
    c
    +2
    • 5
    • 14
  • r

    Ryan Pierce

    10/15/2020, 1:19 AM
    Will
    onItemClick
    actually get inlined? I inlined it with the intention to improve performance, but I haven't seen
    inline
    used in a constructor before.
    class MyAdapter(private inline val onItemClick: (Item) -> Unit) {
       //...
    }
    m
    • 2
    • 5
  • m

    Mark Buikema

    10/15/2020, 9:25 AM
    Hi devs, a question not related to kotlin: In git, for big feature branches, what prefix do you use for the branch?
    v
    k
    • 3
    • 2
  • r

    ron

    10/15/2020, 12:17 PM
    Question ❓ to Jetbrains we are starting a kotlin users group is there something like a info or get started package?
    a
    • 2
    • 2
Powered by Linen
Title
r

ron

10/15/2020, 12:17 PM
Question ❓ to Jetbrains we are starting a kotlin users group is there something like a info or get started package?
a

Alejandro Rios

10/15/2020, 12:19 PM
besides this: https://kotlinlang.org/user-groups/branding.html not sure if there's a get started package
r

ron

10/15/2020, 2:39 PM
Thanks 🙂 we will use that
View count: 2