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

    CLOVIS

    02/19/2020, 1:02 PM
    What are the main differences between
    Iterator
    and
    Sequence
    ?
    s
    m
    f
    • 4
    • 10
  • l

    Leon K

    02/19/2020, 1:04 PM
    Sequence
    is lazy
    m
    f
    • 3
    • 11
  • l

    Leon K

    02/19/2020, 2:32 PM
    is there a
    Map<K, V>.putAllWith(other: Map<K, V>, remappingFunction: (V, V) -> V): Map<K,V>
    equivalent?
    e
    d
    • 3
    • 6
  • j

    jojo.lichtenberger

    02/19/2020, 2:58 PM
    public interface ResourceManager<R extends NodeReadOnlyTrx & NodeCursor, W extends NodeTrx & NodeCursor>
    d
    t
    • 3
    • 5
  • r

    rook

    02/19/2020, 5:33 PM
    Is there a way to check if a
    lateinit var func: () -> Unit
    has been initialized? Or, if there’s a better strategy for this, I’m open to other solutions.
    a
    s
    d
    • 4
    • 6
  • c

    Chills

    02/20/2020, 1:06 AM
    Unresolved reference: JsonFeature even after adding
    // <https://mvnrepository.com/artifact/io.ktor/ktor-client-features>
    compile group: 'io.ktor', name: 'ktor-client-features', version: '1.3.0'
    // <https://mvnrepository.com/artifact/io.ktor/ktor-client-json>
    compile group: 'io.ktor', name: 'ktor-client-json', version: '1.3.0'
    // <https://mvnrepository.com/artifact/io.ktor/ktor-client-apache>
    compile group: 'io.ktor', name: 'ktor-client-apache', version: '1.3.1'
    p
    • 2
    • 5
  • c

    Chills

    02/20/2020, 3:02 AM
    is there any gradle plugin to convert java files to kotlin files?
    j
    c
    • 3
    • 2
  • b

    Burkhard

    02/20/2020, 9:05 AM
    Is unicode encoding in string literals working as it is supposed to? I’m trying to encode a Flag emoji character. They are encoded as to regional indicators, basically the 2 char country iso code. So a german flag would be
    \u1f1e9\u1f1ea
    but for some reason only the first 4 chars of each unicode codepoint are recognized as part of the character. Do I have to encode unicode codepoints as a surrogate pair if they aren’t part of the BMP or is there a better way to do this?
    s
    • 2
    • 11
  • m

    Mikael Alfredsson

    02/20/2020, 9:32 AM
    is this an evaluation bug, or do I miss something?
    s
    k
    • 3
    • 9
  • a

    activesince93

    02/20/2020, 11:10 AM
    Greetings! We would like to welcome you to participate in the 2nd Edition of the Unifynd Hackathon. "The Artificial Intelligence & Deep Learning (AIDL) Hackathon 2020" Participate and create winning solutions for this year's problem statements and stand a chance to win cash prizes up to 50k! Theme - Image Processing & Text Analysis Problem Statement-1 Image processing & Text extraction: Detecting bill/invoice from given images. Step 1 - Edge detection, cropping, flattening, enhancement of cropped image and compression. Step 2 - Extracting text from the processed image. Problem Statement-2 Develop a solution to extract necessary data points from bills/invoices. Input will be in the form of images. The objective is to extract store name, date of invoice, invoice number, bill amount, store address and items from the given bill. Prizes Winner: 50k Runner-up: 25k *Job opportunities for MVPs Eligibility* Team: 1-4 members. Skills: Problem-solving, Data Structure, Algorithm, Coding. Important Info: The number of participants is strictly limited to 150. Registrations close on 2nd March Register now hackathon.unifynd.com
    t
    p
    • 3
    • 3
  • b

    Bernhard

    02/20/2020, 12:28 PM
    I want a set that retains insertion order, is a sorted set the wrong type?
    d
    k
    +2
    • 5
    • 13
  • b

    Bernhard

    02/20/2020, 12:40 PM
    are all Sets in Kotlin LinkedHashSet?
    s
    • 2
    • 6
  • o

    otakusenpai

    02/20/2020, 1:30 PM
    can anyone tell me why this error iss happening
    java.lang.ArrayIndexOutOfBoundsException: Index 6 out of bounds for length 6
    In this code
    fun getMarketMap(stats: MarketStats): Map<String,MarketResponse> {
            var map = mutableMapOf<String,MarketResponse>()
            for(i in 0 until (stats.marketPrice.size)) {
                println("$i th: ${locations[i]}")
                map[locations[i]] = stats.marketPrice[i]
            }
            return map
        }
    and if possible any way to improve the code
    d
    j
    +2
    • 5
    • 13
  • a

    adnigam

    02/20/2020, 1:52 PM
    Can anyone post kotlin interview questions?
    🙂 1
    a
    r
    +4
    • 7
    • 6
  • k

    kevin.cianfarini

    02/20/2020, 3:09 PM
    I'm trying to do some constructor delegation and I'm getting the error
    There's a cycle in the delegation calls chain
    and I'm not quite sure why. Does anyone know how to fix this?
    internal class EmptyComponentModel private constructor(
        override val countryCode: CountryCode,
        override val saleStatus: SaleStatus,
        override val price: Monetary? = null,
        override val saleNotes: String? = null
    ) : PlacardComponentModel(ListingSaleType.Unknown) {
    
        constructor(countryCode: CountryCode, saleStatus: SaleStatus) : this(
            countryCode = countryCode,
            saleStatus = saleStatus
        )
    }
    s
    • 2
    • 9
  • c

    Chills

    02/20/2020, 3:53 PM
    how to parse xml with kotlinx-serializer?
    d
    • 2
    • 5
  • b

    Bob Glamm

    02/20/2020, 7:20 PM
    Ugh, IntelliJ editing performance is absolutely terrible with Kotlin. 3GB of RAM allocated to IJ and it slows to a crawl with lots of multi-second GC pauses between keystrokes. Are there any workarounds for this or any fixes planned?
    z
    s
    d
    • 4
    • 13
  • h

    Hanno

    02/20/2020, 7:41 PM
    The Problems you describe do happen for us only in gradle.kts files, so you experience problems in regular Kotlin classes as well? If yes, there must be sth wrong, using kotlin super smoothly in pretty big, even mixed projects. I guess you already deactivated all plugins and so on?
    n
    • 2
    • 1
  • g

    Gyuhyeon

    02/21/2020, 6:40 AM
    is it not possible to call a constructor from a constructor in kotlin? ex:
    class A {
        var x: Int = 0
        var y: Int = 0
        constructor(x: Int) {
            this.x = x
        }
        constructor(x: Int, y: Int) {
            this(x + y)
            this.y = y
        }
    }
    is syntax error in kotlin for whatever reason
    a
    m
    d
    • 4
    • 11
  • n

    Nikola Milovic

    02/21/2020, 8:41 AM
    Can I post a stackoverflow question here? I want to move forward and haven't gotten any answers. (I first wanted to ask here on slack but it required quite a bit of code to share) edit: https://stackoverflow.com/questions/60288406/android-kotlin-unit-test-failing-with-io-mockk-mockkexception-no-answer-found-f
    s
    • 2
    • 1
  • t

    tjohnn

    02/21/2020, 9:21 AM
    Hello here, Is there yet a way to make gson deserialization fail whenever it attempts to assign a
    null
    value to a kotlin non-nullable field?
    l
    a
    d
    • 4
    • 11
  • e

    elect

    02/21/2020, 10:05 AM
    any notable difference between
    removeIf((E) -> Boolean)
    and
    removeAll((E)->Boolean)
    ?
    l
    d
    • 3
    • 4
  • f

    frogger

    02/21/2020, 2:27 PM
    How could I roughly optimize this code to run (at least) the slow part “api.fetchEntry(entry)” concurrently? (There is a lot of IO wait here, but parallel fetching works well). The writes must stay in order and there is a max number of document that would fit into memory at the same time (let’s say 100). Just need to hint in the right direction, no running code. For
    api.fetchEntry(entry)
    there is also a variant that returns a
    Future<String>
    for(indexPage in api.fetchIndexIterable()) {
    	for(entry in indexPage) {
    		val document = api.fetchEntry(entry)
    		val changed = computeSomeChanges(document)
    		writeInOrder(changed)
    	}		
    }
    r
    v
    +3
    • 6
    • 28
  • l

    Leon K

    02/21/2020, 2:30 PM
    you can use
    async {}
    coroutine builder and then create a list (of say, max 100 elements) from the resulting `deferred`s, then
    .awaitAll()
    and process them. do this for as many entries as you need, maybe by chunking your entries into blocks of max-length 100 before an then just
    map { async { api.fetchEntry(it) } }.awaitAll()
    :thread-please: 4
    👍 1
    f
    • 2
    • 3
  • i

    iex

    02/21/2020, 5:27 PM
    Given this code:
    data class Flow(
        val ids: List<MyId>,
        val steps: MySteps
    ) {
    
        constructor(ids: List<MyId>) : this(
            ids,
            MySteps(ids.toSteps(), ids.toSteps().first())
        )
    }
    
    data class MySteps(val steps: List<MyStep>, val currentStep: MyStep)
    How can I throw an error in the convenience constructor if
    ids
    is not empty (such that it crashes before
    ds.toSteps().first()
    ?
    w
    s
    +2
    • 5
    • 11
  • e

    elect

    02/21/2020, 6:05 PM
    I need to pass
    vararg args: Any
    down the function stack, in order to format later a
    String
    . However I keep getting
    IllegalFormatConversionException
    logDebug("WindowRef %08X", ref.id) // ref.id is an Int
    
    fun logDebug(fmt: String, vararg args: Any) {
    
       val toAppend = fmt.format(args) // IllegalFormatConversionException
       ...
    }
    i
    t
    • 3
    • 4
  • u

    ursus

    02/21/2020, 11:55 PM
    Why can't I move multiple kotlin files to another package at once? so annoying
    l
    • 2
    • 2
  • h

    Hexa

    02/22/2020, 11:01 AM
    Why I keep getting this compile error:
    Error:(2, 44) Kotlin: Type parameter T is declared as 'in' but occurs in 'invariant' position in type SomeClass<String, T>
    But it compiles when I remove the
    in
    keyword like this:
    abstract class A<T>
    ? Given
    someMethod(item: SomeClass<String, T>)
    takes
    T
    as an input then using
    in
    should work in this case?
    abstract class A<in T> {
        fun someMethod(item: SomeClass<String, T>) {
            println(item)
        }
    }
    
    open class SomeClass<K,V>(
        override val entries: Set<Map.Entry<K, V>>,
        override val keys: Set<K>,
        override val size: Int,
        override val values: Collection<V>
    ) : Map<K,V>{
        override fun containsKey(key: K): Boolean {
            TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
        }
    
        override fun containsValue(value: V): Boolean {
            TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
        }
    
        override fun get(key: K): V? {
            TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
        }
    
        override fun isEmpty(): Boolean {
            TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
        }
    }
    k
    r
    f
    • 4
    • 4
  • p

    Piet Bronders

    02/22/2020, 2:30 PM
    Could someone please explain me the difference between CPointer and CPointerVar? I have been struggling to understand the difference, but haven't been able ot make any headway (or send me to the correct channel that is discussing C_interop in Kotlin if this the wrong one 😢 )
    r
    • 2
    • 2
  • c

    CLOVIS

    02/22/2020, 8:14 PM
    Is there a reason why we can't pass a type as parameter directly, and instead have to use the
    ::
    notation?
    fun foo(a: KClass) = ...
    foo(String) // Illegal
    foo(String::class) // Legal
    s
    • 2
    • 4
Powered by Linen
Title
c

CLOVIS

02/22/2020, 8:14 PM
Is there a reason why we can't pass a type as parameter directly, and instead have to use the
::
notation?
fun foo(a: KClass) = ...
foo(String) // Illegal
foo(String::class) // Legal
I know about reifed types that allow a simpler syntax, but my question is more about why it was made this way
It looks more Java-like this way, but apparently Scala did it the other way. I guess it's because it removes some ambiguity somewhere, but I don't see in which case it's a problem...
s

streetsofboston

02/22/2020, 8:41 PM
Because
String
would refer to its companion object (if it had one 😀)
👍 1
c

CLOVIS

02/23/2020, 3:46 PM
Oh. Yeah that was more obvious than I expected XD
View count: 4