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

    hho

    09/26/2017, 2:53 PM
    listOf(1, 2, 3, 4, 5, 6).chunked(2, { it[0] to it[1] }).toMap()
    seems to work, but you're creating a
    List
    for every map entry... (EDIT: Cleaned up thanks to karelpeeters)
    i
    • 2
    • 1
  • k

    karelpeeters

    09/26/2017, 2:54 PM
    (You can use
    to
    to clean that up a bit, and
    it[0]
    for that matter)
    h
    • 2
    • 2
  • h

    hho

    09/26/2017, 3:20 PM
    FWIW: https://github.com/Kotlin/KEEP/issues/11#issuecomment-332233555
    a
    • 2
    • 2
  • k

    kozhuhar.kirill

    09/27/2017, 12:15 PM
    fun main(arr: Array<String>) { var b: Int? = null listOf("a", "b", "c").forEach { b?.let { println("${b + 1}") } } }
    m
    • 2
    • 3
  • k

    kozhuhar.kirill

    09/27/2017, 12:32 PM
    https://kotlinlang.slack.com/archives/C0B8MA7FA/p1506509062000191
    k
    • 2
    • 1
  • s

    sureshbabuinfo

    10/01/2017, 6:55 PM
    Thank you @karelpeeters . Here @value is spring annotation. Spring will substitute it’s value from properties file during runtime
    k
    • 2
    • 1
  • p

    Prateek

    10/01/2017, 6:55 PM
    @karelpeeters do you agree that by default the var/val in a kotlin class is public?
    k
    • 2
    • 10
  • j

    jtonic

    10/02/2017, 7:00 PM
    Hi. In my kotlin project (maven based) I was trying to configure the compiler switch -Xjsr305=warn, to instruct kotlin compiler to emit warns instead of errors. But I didn’t manage to make it work. - In idea I put this compiler flag in additional command line parameters. - In maven I put the following:
    <plugin>
            
            <artifactId>kotlin-maven-plugin</artifactId>
            <version>${kotlin.version}</version>
    				<configuration>
    					
    					<jvmTarget>${java.version}</jvmTarget>
              <args>
                -Xjsr305=warn
              </args>
    Do you have any idea how can I config it? Thank you in advance.
  • k

    karelpeeters

    10/03/2017, 7:48 AM
    That's not how maps work, they don't really have an order most of the time.
    s
    • 2
    • 2
  • g

    genovich

    10/03/2017, 9:38 AM
    Looks like issue
    k
    • 2
    • 1
  • s

    stepan.zalis

    10/03/2017, 5:11 PM
    Hi, I have a stopwatch in recyclerview.. Evyrything works fine until I start to scrolling and holders are reused.. Problem is that the holder should be empty, but it is “ticking”, because it is reused, any ideas? I hotfixed it to set holder not to be reusable, but it is paining
    k
    • 2
    • 3
  • j

    jb

    10/04/2017, 4:18 PM
    all, I'm working through the kotlin koans, but the generics section trips me up a bit. I've been away from java for sometime, so humour me. In "fun <T, C:MutableCollection<T>> Collection<T>.partitionTo(first: C, second: C, predicate: (T) -> Boolean): Pair<C, C>", how should one read "<T, C: MutableCollection<T>>"? As I understand it, the code preceding the function name is the type parameter...but in this case, what is it stating the type is? The "," is throwing me for a loop...
    p
    • 2
    • 10
  • v

    vicpinm

    10/05/2017, 7:56 AM
    Do you mean something like B.plus(A)?
  • v

    vicpinm

    10/05/2017, 7:57 AM
    If I do that, B items are not updated with A items with same id, B items are updated only with new A items that are not in B
    v
    e
    • 3
    • 3
  • v

    vicpinm

    10/05/2017, 10:39 AM
    A + B produces the same result
    k
    • 2
    • 1
  • l

    lupajz

    10/05/2017, 3:09 PM
    While we are at sequences what are differences between
    buidSequence
    &
    generateSequence
    is it only that the later takes suspendable function ?
    k
    a
    • 3
    • 4
  • r

    Rockstar

    10/05/2017, 3:12 PM
    How to use Kotlin in Android Studio?
    👍 1
    :google: 1
    l
    • 2
    • 2
  • j

    jabba

    10/08/2017, 10:50 AM
    Karel: I think you mistyped. "The receiver is evaluated first, so also will return
    8
    . In the passed lambda, `a`'s value is assigned to `b`" would be the correct way, no?
    k
    • 2
    • 2
  • f

    fstn

    10/09/2017, 9:49 AM
    Ok,I will read more carefully the documentation then 😉
    :google: 3
    l
    e
    • 3
    • 11
  • n

    nil2l

    10/10/2017, 9:34 AM
    DefaultClass<T>::class
    v
    • 2
    • 1
  • k

    karelpeeters

    10/10/2017, 9:35 AM
    Shouldn't it be
    KClass<DefaultClass>
    ? What does the generic parameter on DefaultClass do here?
    v
    n
    • 3
    • 4
  • n

    nil2l

    10/10/2017, 10:59 AM
    There is no
    Foo<T>::class
    at all. You should provide both: class and its parameter.
  • a

    Andreas Sinz

    10/11/2017, 1:47 PM
    @miha-x64 how does your
    RootPresenterTag.get()
    look like?
    m
    • 2
    • 7
  • r

    Rajesh

    10/11/2017, 2:02 PM
    Is it possible to decompile .class files to Kotlin in intellij ? The .class files that are originally kotlin are now decompiled to java. It is much easier to see kotlin code decompiled to kotlin.
    k
    • 2
    • 2
  • a

    ayubi

    10/11/2017, 2:11 PM
    Hello, I am confused between kotson, klaxon, Gson, Jackson with Kotlin module for parsing JSON in Kotlin. Is there any recommendation/standard, usability issues. Asking for a new project. Where my JSON string might have missing data and I want to use immutable data classes. Anything I should consider before going with any one of those? Any comparisons? Performance issues? Any help would be appreciated.
    k
    • 2
    • 2
  • k

    karelpeeters

    10/11/2017, 3:52 PM
    The getter needs to be more at least as visible as the setter if that's what you're talking about.
    👍 1
    s
    r
    • 3
    • 6
  • k

    Karolo

    10/11/2017, 11:31 PM
    Hi, I will jump into discussion with my question, so if iterrupting I am sorry 🙂 I have in object Foo var with custom setter:
    var foo: ((Long) -> Unit)? = null
            set(value) {
                update()
            }
    And the problem is when setting it from another part of code like that:
    Foo.foo = {it-> doSomeJobWithIt(it) }
    it still after such verified call stays null. I am sure that setter is called but somehow my foo inside Foo is still null. Is there something I am missing with variables in object's ? Thanks in advance!
    k
    • 2
    • 4
  • p

    Prateek

    10/12/2017, 5:19 AM
    all fields are correct
    a
    • 2
    • 2
  • t

    todd.ginsberg

    10/12/2017, 3:20 PM
    What the heck did I just run then? I swear that said
    5
    when I ran it... now it says 53. 🤔
    e
    • 2
    • 1
  • f

    fstn

    10/13/2017, 5:04 AM
    Is there a better way than using java Completable to do that kind of things :
    val result= CompletableFuture<String>()
            eventBus.consumer<context.Context>(eventName, this).completionHandler { 
                if(it.succeeded()){
                    <http://logger.info|logger.info>("Register ${this::class.simpleName} for event $eventName")
                    result.complete(this::class.simpleName)
                }else{
                    logger.error("Unable to register ${this::class.simpleName} for event $eventName")
                    result.completeExceptionally(UnableToRegisterServiceTaskException())
                }            
            }
            return result
    u
    • 2
    • 1
Powered by Linen
Title
f

fstn

10/13/2017, 5:04 AM
Is there a better way than using java Completable to do that kind of things :
val result= CompletableFuture<String>()
        eventBus.consumer<context.Context>(eventName, this).completionHandler { 
            if(it.succeeded()){
                <http://logger.info|logger.info>("Register ${this::class.simpleName} for event $eventName")
                result.complete(this::class.simpleName)
            }else{
                logger.error("Unable to register ${this::class.simpleName} for event $eventName")
                result.completeExceptionally(UnableToRegisterServiceTaskException())
            }            
        }
        return result
u

uli

10/13/2017, 12:08 PM
Take a look at Kotlin coroutines. It typically enables you to write clean, sequential code for your concurrent tasks
View count: 2