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

    arnaud.giuliani

    12/06/2017, 3:02 PM
    Hello guys, as a Kotlin library provider, is it better to always provide my framework at latest Kotlin version (i.e. 1.2) or stay a while on most stable ?
    c
    k
    • 3
    • 4
  • g

    GauthierPLM

    12/06/2017, 4:46 PM
    I just randomly discovered kotlin Sequences (https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.sequences/index.html) while reading the AMA on Reddit. Is it mentioned in the doc (other than the reference) ? It would be nice to talk about it in the page of collection as it could be really useful. Also a tutorial on laziness would be nice. i think i could use it in my app, but don’t know yet how to do that.
    a
    • 2
    • 2
  • j

    joshua.ewer

    12/06/2017, 7:19 PM
    anyone have a good idiom for solving this problem?
    given two nullable lists,
    a: List<String>?
    and
    b:List<String>?
    if any are not null, return a concat list
    else return null
    g
    • 2
    • 1
  • e

    elizarov

    12/06/2017, 7:29 PM
    b?.let { a?.plus(it) ?: it } ?: a
    to return null only if both are null
    c
    • 2
    • 2
  • b

    bj0

    12/06/2017, 7:30 PM
    ?: it
    e
    • 2
    • 1
  • j

    joshua.ewer

    12/06/2017, 7:48 PM
    after writing a handful of tests i ended up going with leo’s suggestion since the logic did get lost in the ?.{}?.?{} soup. super helpful conversation though
    d
    • 2
    • 1
  • j

    jmfayard

    12/06/2017, 7:58 PM
    I have a Kotlin first world problem. After doing backend and Android in Kotlin, I don't know what I want to try out first: Kotlin react js, multiplatform or tornado FX?
    n
    • 2
    • 3
  • j

    jtonic

    12/07/2017, 6:05 AM
    Dear Kt community, Could you please emphasise why the following compilation error occurs.
    Error:(13, 30) Kotlin: Type checking has run into a recursive problem. Easiest workaround: specify types of your declarations explicitly
    in the following case
    package ro.jtonic.tutorials.kt.oop.miscs
    
    private const val PI = Math.PI
    const val E = Math.E
    
    private fun computePi() = PI
    fun computeE() = E
    
    class MyMath {
    
        val E = FilePrivateUtils@::E.get() // here is the compilation error
        val pi = FilePrivateUtils@::PI.get()
    
        fun computingPi() = FilePrivateUtils@::computePi.invoke()
        fun computingE() = FilePrivateUtils@::computeE.invoke()
    }
    Thank you.
    a
    i
    • 3
    • 7
  • r

    Ruckus

    12/07/2017, 4:46 PM
    @abreslav I've seen you mention several times that you think companion objects could have been done better, and in the AMA you said you may be able to fix that in the future. Is there any chance you could elaborate on what you see as shortcomings to the current implementation and how it might be improved?
    a
    • 2
    • 2
  • c

    cedric

    12/07/2017, 6:42 PM
    Given
    data class Foo(var s: Int? = null)
    , is it possible to invoke the default constructor by reflection without requiring
    @JvmOverloads
    ? Without it, I see that this class has two constructors, one with a last parameter
    DefaultConstructorMarker
    but it doesn’t look like I can invoke it.
    k
    • 2
    • 1
  • a

    adams2

    12/07/2017, 7:10 PM
    does the initialization call my custom setter?
    a
    • 2
    • 1
  • t

    Thiago

    12/07/2017, 8:02 PM
    I did not understand.
    r
    e
    • 3
    • 4
  • e

    emmanuelvinas

    12/08/2017, 9:03 AM
    Someone knows if the video of yesterday's webinar by @yole is available ?
    y
    • 2
    • 4
  • m

    michaelzinn

    12/08/2017, 10:27 AM
    For those who are stuck with a Java project that you can’t port to Kotlin I backported Kotlin’s null safety to Java (meta-annotation, ?. and ?:) : https://github.com/cosee/null4j
    👍 1
    d
    • 2
    • 4
  • m

    michaelzinn

    12/08/2017, 10:52 AM
    x?.let { bla(it) }
    becomes
    let(x, Bla::bla)
    for example.
    i
    • 2
    • 2
  • k

    karelpeeters

    12/08/2017, 11:53 AM
    Because it can also be used in
    when
    and
    for
    statements, where it has a slightly different meaning.
    s
    • 2
    • 10
  • t

    Thiago

    12/08/2017, 2:19 PM
    Helllo @agrosner I'm having the following error in my project: Error: error: * ========== * class com.raizlabs.android.dbflow.processor.TableValidator: Table Value must provide a visible, default constructor. * ========== * However, I checked the link https://github.com/Raizlabs/DBFlow/issues/1463 that for item 3, you suggest that 'Make sure you provide default values for all fields.' However, all fields in the data class begin with the value null. What would be the solution to this case? Would you help me? Os campos do data class sao : @Column @PrimaryKey(autoincrement = true) var id: Long? = null, @Column var example_value: String? = null, @Column var example_value: String? = null, @Column var example_value: String? = null, @Column var example_value: Int? = null, @Column var example_value: String? = null, @Column var example_values: String? = null, @Column @SerializedName("active") var isActive: Boolean? = null, @Column @Transient var example_value: Int? = null, @Expose var example_value: List<example_value>? = null)
    :stackoverflow: 2
    a
    k
    l
    • 4
    • 8
  • n

    nickk

    12/08/2017, 3:30 PM
    I tried to overcome the JVM type erasure by storing the Type at compile time, like so:
    data class ResultWrapper<out T>(val request: RequestInfo, val obs: T, val typeOfResult : KClass<*>? = null)
    However doing a
    when
    on the
    typeOfResult
    field does not work:
    when (item.typeOfResult) {
                 is Enemy -> {
                      messages.add("Received instance of type ${item.typeOfResult.simpleName} !")
                  }
    Any ideas/suggestions?
    v
    d
    • 3
    • 4
  • e

    evan

    12/08/2017, 10:20 PM
    This piece of code does not compile:
    val byteVal:Byte = 0
    val isZero = byteVal == 0
    You have to change it to this to make it compile (and run):
    val byteVal:Byte = 0
    val isZero = byteVal == 0.toByte()
    This seems overly complicated to just compare a byte-value with a literal. Do we really have to call a method (
    toByte()
    ) to do this? Is there a modifier (much like
    L
    for longs and
    f
    for floats) to make this simpler and less expensive?
    i
    • 2
    • 1
  • k

    karelpeeters

    12/09/2017, 8:57 PM
    Because transforming it into a map only "works" when your map function is injective.
    g
    • 2
    • 4
  • m

    mc

    12/10/2017, 1:12 PM
    Hi, is there a reason why the following class wouldn't compile?
    class Example {
    
        private val backingMap = mutableMapOf<String, MutableSet<String>>()
    
        fun addVertex(v: String): Boolean = backingMap.putIfAbsent(v, mutableSetOf()) == null
        
        fun addEdge(v: String, w: String): Boolean {
            listOf(v, w).map(::addVertex)
            return backingMap[v]!!.add(w)
        }
    
    }
    l
    k
    • 3
    • 4
  • r

    robfletcher

    12/10/2017, 7:29 PM
    I have 2 methods
    fun <ACTUAL> expect(
      actual: ACTUAL,
      block: ObjectAssert<ACTUAL>.(ACTUAL) -> Unit
    ): ObjectAssert<ACTUAL>
    and
    fun <ELEMENT> expect(
      actual: List<ELEMENT>,
      block: SoftAssertionListAssert<ELEMENT>.(List<ELEMENT>) -> Unit
    ): SoftAssertionListAssert<ELEMENT>
    that the compiler is unable to distinguish between at the call site. I get why that’s an issue but confusingly I have overloads of both that only accept the first parameter:
    fun <ACTUAL> expect(actual: ACTUAL): AbstractObjectAssert<*, ACTUAL>
    and
    fun <ELEMENT> expect(actual: List<ELEMENT>): ListAssert<ELEMENT>
    that the compiler can distinguish. Can anyone enlighten me as to why one is a problem and no the other? Is there any way I can disambiguate the 2 param form?
    k
    a
    • 3
    • 11
  • p

    pakoito

    12/10/2017, 8:41 PM
    https://github.com/scala/scala/blob/v2.12.0/src/library/scala/collection/mutable/ArrayStack.scala#L1
    c
    • 2
    • 3
  • m

    Marcin Wisniowski

    12/11/2017, 6:06 AM
    I'm wondering if it's preferred to call a function when using
    map
    or pass a method reference:
    listOf("1", "2", "3").map { it.toInt() }
    listOf("1", "2", "3").map(String::toInt)
    Is either of these considered better? (Or am I overthinking this?)
    c
    p
    c
    • 4
    • 7
  • k

    karelpeeters

    12/11/2017, 8:45 AM
    Ah, gotcha, didn't see the
    \n
    .
    str.split("\n").map { it.split("\t").map { it.toInt() } }
    k
    c
    • 3
    • 4
  • e

    edwardwongtl

    12/11/2017, 10:34 AM
    Maybe you can also check #opensource
    l
    o
    • 3
    • 2
  • s

    Slackbot

    12/11/2017, 1:00 PM
    This message was deleted.
    c
    • 2
    • 1
  • l

    lovis

    12/11/2017, 1:11 PM
    is there a way to configure "convert java to kotlin", to use
    public
    instead of
    internal
    when the visibility was
    package-private
    before? 🤔
    h
    c
    • 3
    • 2
  • e

    EDesigner250

    12/11/2017, 2:06 PM
    can kotlin work with Spark
    m
    • 2
    • 3
  • s

    stkent

    12/11/2017, 4:13 PM
    Is there a way to perform a
    fold
    and access the intermediate values?
    i
    • 2
    • 2
Powered by Linen
Title
s

stkent

12/11/2017, 4:13 PM
Is there a way to perform a
fold
and access the intermediate values?
i

ilya.gorbunov

12/11/2017, 6:32 PM
Looks like `scan`: https://youtrack.jetbrains.com/issue/KT-7657 Could you share your use case there?
s

stkent

12/11/2017, 6:38 PM
Yup, exactly that. My use case is the same as Andy Bowes'; it came up during advent of code (mapping a list of steps to create the entire path, not just the end location)
View count: 1