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

    ursus

    07/22/2018, 3:24 PM
    WHEN_ENUM_CAN_BE_NULL_IN_JAVA
    is so annoying, then my enum is in kotlin
    k
    d
    • 3
    • 40
  • b

    benleggiero

    07/22/2018, 9:02 PM
    Is there a preferred database strategy in Kotlin?
    k
    a
    • 3
    • 3
  • g

    Giulio

    07/23/2018, 6:21 PM
    is there a good, complete example on github of android app developed in Kotlin? Or a free tutorial to build an android app with a nice UI? Thank you!
    k
    a
    j
    • 4
    • 10
  • p

    pyrkamarcin

    07/24/2018, 9:06 PM
    Hi! I need convert string bellow to valid JSON:
    {
    ChallengeParameters: {},
    AuthenticationResult: {
    AccessToken: eyJraWQiOiI3Qnw,
    ExpiresIn: 3600,
    TokenType: Bearer,
    RefreshToken: yJjdHkiOCcr
    }
    }
    There is simple solution?
    r
    o
    n
    • 4
    • 3
  • p

    pyrkamarcin

    07/24/2018, 9:21 PM
    @karelpeeters yup. This is simple. I need add only
    .
    and
    -
    (internal token char) in regex and run.
    k
    o
    • 3
    • 14
  • l

    locke

    07/25/2018, 4:31 PM
    Is there a simple way to convert a
    List<Pair<T,S>>
    to
    Map<T,S>
    ?
    m
    • 2
    • 1
  • i

    ivano

    07/25/2018, 4:53 PM
    but I do not know how generics work with two parameters
    l
    • 2
    • 4
  • s

    stegod10

    07/26/2018, 8:28 AM
    Looking for your suggestion. I just want to draw a path on map and then directive people for that rotate.
    d
    • 2
    • 1
  • a

    Arvind Katte

    07/26/2018, 9:12 AM
    Hi All, I have 3+ years of experience on Java, let me know from where I should start learning Kotlin
    c
    a
    • 3
    • 5
  • a

    albertm

    07/26/2018, 3:34 PM
    Hi guys, just a quick question, I was trying to make this:
    with(dataList as RecyclerView) {
                layoutManager = createNewLayoutManager()
     ....
    }
    So I have the RecyclerView and set all the params, but it's not working. It works only if I make the direct cast like this: (dataList as RecyclerView).layoutManager = createNewLayoutManager() What I am doing wrong?
    k
    • 2
    • 1
  • h

    Hadi Tok

    07/26/2018, 9:51 PM
    how do I map a single object to some other object? for example with
    val key:String? = getKey() ; key?.mapSingle{ getValue(it) }?.{println(it)}
    what should keyword should replace
    mapSingle
    r
    • 2
    • 3
  • m

    martmists

    07/29/2018, 2:31 PM
    How do I turn Java code into Kotlin code? I've heard Intellij can do it automatically, but how do I do it in notepad++?
    a
    k
    k
    • 4
    • 5
  • m

    martmists

    07/29/2018, 2:36 PM
    How do I create a zip file in memory only, using files from a relative directory?
    g
    • 2
    • 1
  • m

    martmists

    07/29/2018, 2:49 PM
    Because I can't find anything that allows me to both read and write to a ZipFile object or ZipFile...Stream
    c
    • 2
    • 1
  • n

    Niko

    07/30/2018, 9:37 AM
    I have a more general question: Does anyone know a good article which points out the reasons why I should move from Java to Kotlin? I want to introduce kotlin within my company and I am looking for every good document to show my colleagues all advantages of Kotlin. As I am at a beginning point by myself it would be great to have knowledge based articles and stuff like that. Thanks for help!
    a
    k
    +2
    • 5
    • 5
  • a

    Alhima

    07/30/2018, 3:30 PM
    Hello! I have a question about the language, please if Im in the wrong channel tell me. I have two variables in a class, one is a
    lateinit var myVariable1
    that will be injected later and another one is a val that is initialised by a extension function that returns a
    lazy
    with the function that initialises my
    variable2
    (this extension needs my previous
    lateinit var myVariable1
    by parameter) . When Im creating my class, Im receiving an error because the ´lateinit var myVariable1´ is null at the moment that the class is created(and lateinit cannot be null). Shouldnt this be protected? As Im using only that` lateinit var myVariable1` parameter in my lazy function, that will be triggered always after my ´lateinit var´ is injected?
    h
    • 2
    • 2
  • u

    ursus

    07/30/2018, 7:50 PM
    how can I write for loop with condition?
    var i = 0
    while (i < Math.min(all.size, maxSize)) {
    }
    other than while, so I can keep the i var indite the loop scope
    l
    d
    k
    • 4
    • 4
  • u

    ursus

    07/30/2018, 8:24 PM
    id like to also ask how to rewrite this in more functional style
    val maxSize = BookDao.RECENTS_SIZE
    val all = mutableListOf<RealmObject>()
    all.addAll(it.findAllRecentSearchedBooks().run { if (this.size > maxSize) subList(0, maxSize) else this })
    all.addAll(it.findAllRecentSearchedAuthors().run { if (this.size > maxSize) subList(0, maxSize) else this })
    
    all.sortByDescending {
    	when (it) {
    	        is RecentlySearchedBook -> it.timestamp
    	        is RecentlySearchedAuthor -> it.timestamp
    	        else -> error("Unknown type")
            }
    }
    
    val allUnmamaged = mutableListOf<SearchItem>()
    for (i in 0 until Math.min(all.size, maxSize)) {
    	allUnmamaged.add(it.unmanaged(all[i]) as SearchItem)
    }
    
    allUnmamaged
    d
    • 2
    • 29
  • t

    tipsy

    07/31/2018, 2:24 PM
    can you make all the functions on an object static by annotating the object itself?
    v
    k
    +2
    • 5
    • 6
  • k

    karelpeeters

    07/31/2018, 9:09 PM
    Is there no buildin comparator for booleans? Like there is
    nullFirst
    for nulls.
    h
    • 2
    • 2
  • u

    ursus

    08/01/2018, 1:19 AM
    is there a way I can initialize my arrays in a loop, without them being of nullable items?
    d
    • 2
    • 3
  • u

    ursus

    08/01/2018, 2:10 AM
    is there nicer way, to lazy initialize nullable property, without then using !! ?
    h
    • 2
    • 1
  • a

    Aregev2

    08/01/2018, 10:29 AM
    How do I make it correct (i.e: how to access
    print()
    in this case)
    s
    k
    d
    • 4
    • 7
  • u

    ursus

    08/01/2018, 3:56 PM
    Why cant I have public propety with public setter and private getter?
    a
    • 2
    • 2
  • b

    Bernhard

    08/01/2018, 7:25 PM
    am I looking for let?
    a
    d
    s
    • 4
    • 4
  • b

    bdawg.io

    08/01/2018, 9:34 PM
    I want to perform a
    reduce
    operation but I want my accumulator value to be a different type than the types and I want to provide my initial value. Here’s an example using Int and String
    listOf("1", "10", "100", "1000").reduce(withInitial = 0) { acc: Int, current: String ->
        acc + current.toInt()
    } // should result in Int(1111)
    i
    • 2
    • 2
  • b

    Bernhard

    08/02/2018, 11:50 AM
    as in: null safe?
    d
    • 2
    • 2
  • k

    karelpeeters

    08/02/2018, 12:44 PM
    Yeah that's the point of a conversion tool isn't it?
    👍 1
    a
    • 2
    • 1
  • a

    Aregev2

    08/02/2018, 1:18 PM
    Whats POLA? Yes it works
    s
    • 2
    • 2
  • z

    zpearce

    08/02/2018, 7:42 PM
    is there a stdlib function that will call a lambda for each element in an iterable, and return the iterable at the end? Or am I stuck with
    mylist.map { doTheThing(it); it }
    d
    • 2
    • 2
Powered by Linen
Title
z

zpearce

08/02/2018, 7:42 PM
is there a stdlib function that will call a lambda for each element in an iterable, and return the iterable at the end? Or am I stuck with
mylist.map { doTheThing(it); it }
d

diesieben07

08/02/2018, 7:42 PM
onEach
👆 1
z

zpearce

08/02/2018, 7:46 PM
ah, thx! I didn't make it far enough in the docs before I gave up, apparently 😉
View count: 14