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

    ValV

    10/22/2018, 10:34 PM
    I dunno where to ask this question, though... Oracle's Java SE 11 implementation is called Oracle JDK, while the same things for Java SE 8 were called either JDK, JRE Server, or just JRE, depending on packaging. Why for Java SE 11 they add Oracle prefix to their JDK/JRE (as well as to Oracle OpenJDK)? How to refer to Oracle's distribution of Java SE 8 -- just JDK/JRE?
    s
    • 2
    • 6
  • s

    Slava Kornienko

    10/22/2018, 10:52 PM
    Привет! Как можно логировать тело запросов? Кроме их метода и пути
    p
    • 2
    • 1
  • s

    Slava Kornienko

    10/22/2018, 11:01 PM
    Sorry, I thought it was ktor slack
    r
    • 2
    • 1
  • p

    pavel

    10/23/2018, 6:12 PM
    doesn’t work on try.kotlinlang.com with JVM and 1.2.71
    h
    • 2
    • 1
  • j

    jacob

    10/24/2018, 5:05 AM
    #arrow will likely get you more eyes on the question @vejeta
    v
    • 2
    • 1
  • s

    Sudhir Singh Khanger

    10/25/2018, 5:51 PM
    CHEESE_DATA.map { Cheese(id = 0, name = it) }
    CHEESE_DATA
    is an ArrayList. If we apply
    map
    with the above function then should it not create a list of Cheese objects with id
    0
    and name
    it
    . The result seems to be Cheese object with an incremented value for id and
    it
    name. What am I missing? https://github.com/googlesamples/android-architecture-components/blob/6248bed977e7a82d6f3199e8a940a39b7d6f051c/PagingSample/app/src/main/java/paging/android/example/com/pagingsample/CheeseDb.kt#L54
    a
    l
    • 3
    • 6
  • m

    mics

    10/25/2018, 5:58 PM
    Hi, I’m looking for a way around a compilation error when interacting with specific Java code. I have a preexisting Java code (in a library, which I cannot change and need to consume) the code like this
    class Foo<T extends Enum<T>> {
      Foo(Class<T> type) {}
    }
    
    enum FEnum {
      BLAH
    }
    and then I try to instantiate
    Foo
    in Kotlin
    fun main(args: Array<String>) {
        val foo = Foo(FEnum::class.java) // works ok, but have to hard-code enum class name here
    
        val type: Class<out Enum<*>> = FEnum::class.java
        val bar = Foo(type) // Error: doesn't work when class is obtained dynamically 
    }
    How can I modify the Kotlin code, passing
    type
    as some
    Class
    , so that
    Foo
    constructor accepts it?
    a
    • 2
    • 8
  • s

    Steven McLaughlin

    10/26/2018, 7:43 PM
    I am working on a small project for fun, and I'm having a little trouble with setting things up with gradle/kotlin 1.3. (Going to post more in a thread so I don't spam the channel)
    h
    d
    • 3
    • 8
  • k

    karelpeeters

    10/29/2018, 3:03 PM
    list.fold(mapOf()) { a, c -> a + c }
    h
    p
    j
    • 4
    • 10
  • j

    jasoet

    10/30/2018, 1:34 AM
    If anyone interested boilerplate Kotlin Project using Gradle you can use this https://github.com/jasoet/kotlin-gradle-boilerplate Update to Kotlin 1.3.0
    n
    m
    • 3
    • 8
  • e

    Enrico Hofmann

    10/30/2018, 12:36 PM
    hi togeth i am a java developer. and i will hove something like nullable/optional in a data class. how can i do that ?
    r
    k
    • 3
    • 3
  • p

    prabello

    10/31/2018, 11:57 AM
    i tried doing
    let{::loveThePet}
    but the return end up beign different and could not chain the calls, they were returning a KFunction instead of the result
    s
    • 2
    • 7
  • m

    Matheus

    10/31/2018, 12:00 PM
    or let(::loveThePet)
    ☝️ 2
    p
    a
    • 3
    • 3
  • j

    jcechace

    10/31/2018, 1:21 PM
    Any hints how to properly configurate shadow plugin? Getting these errors and since I have very limited experience with gradle and shadow plugin it’s not clear wha’t wrong (except for that some things are obviously missing) https://gist.github.com/jcechace/96e8dd2801b677a50a87cebb42e81748
    n
    • 2
    • 16
  • o

    oday

    10/31/2018, 1:52 PM
    ahhh
    m
    • 2
    • 31
  • e

    epchris

    10/31/2018, 3:57 PM
    (I feel like this is a real newb question….)
    s
    • 2
    • 2
  • p

    prabello

    10/31/2018, 7:16 PM
    Does lazy initialization variables have an especific order?
    r
    • 2
    • 3
  • s

    Sudhir Singh Khanger

    11/01/2018, 6:26 AM
    How does
    val that : Int -> Int = { three -> three }
    fit the definition
    val lambdaName : Type = { argumentList -> codeBody }
    ? https://www.baeldung.com/kotlin-lambda-expressions
    n
    • 2
    • 5
  • g

    Gabriel Machado

    11/01/2018, 2:11 PM
    What happens when a function is overriden by a inline function? The compiler warns
    Override by an inline function
    , does this means it won't be inlined?
    o
    • 2
    • 1
  • o

    oday

    11/01/2018, 7:56 PM
    what’s a kotliny way of using
    find
    to find the one and only item in a list where I know there is no repetition with, according to its ID?
    d
    • 2
    • 8
  • h

    Hamza

    11/02/2018, 5:26 AM
    i’ve completely forgotten and i can’t remember how/find anywhere onlein, but how can i add a compiler argument via gradle dsl? i can’t remember for the life of me
    s
    s
    • 3
    • 3
  • d

    dvlwj

    11/02/2018, 8:25 AM
    ktor?
    d
    h
    o
    • 4
    • 13
  • d

    dvlwj

    11/02/2018, 8:41 AM
    is it bad ? i found people saying they are prefer retrofit or okhttp over Fuel.
    h
    • 2
    • 1
  • j

    Jimmy

    11/02/2018, 10:05 AM
    Hello all, I have a question regarding “find{ }” . I checked the code in stdlib and it returns the element or null. I want to return true/false when iterating over a list and certain condition is met. This is what I thought (I bet there is a better way to cover the null case...), any idea??? :
    -.kt
    s
    k
    • 3
    • 5
  • m

    Matouš Skála

    11/02/2018, 10:44 AM
    What's currently the recommended way for creating a Kotlin/Native module that would be used both as an iOS framework and an Android library? After some research, I have found there are three Gradle plugins that I can use: 1. konan (https://kotlinlang.org/docs/tutorials/native/gradle-for-kotlin-native.html) 2. platform.native (https://kotlinlang.org/docs/reference/native/gradle_plugin.html) 3. multiplatform (https://kotlinlang.org/docs/reference/building-mpp-with-gradle.html)
    m
    • 2
    • 3
  • b

    bodiam

    11/02/2018, 11:10 AM
    anyone a suggestion on how to fix this?
    k
    • 2
    • 9
  • b

    bodiam

    11/02/2018, 12:07 PM
    Try Math.min(2,3)
    n
    i
    • 3
    • 4
  • v

    ValV

    11/03/2018, 10:23 AM
    Why sometimes IDEA shows file extensions .kt? Is this because it does not find a class with the same name inside?
    a
    • 2
    • 4
  • s

    scottiedog45

    11/03/2018, 10:28 AM
    Hi everyone! Happy to be here. I have a background in web and iOS but I’m completely new to kotlin. Is kotlin to java as swift is to objc? Are the development environments similar? Is there an xcode parallel for kotlin?
    d
    m
    • 3
    • 2
  • c

    ckchen

    11/03/2018, 12:44 PM
    I am learning coroutines and I got confused when I see the code
    coroutineContext[Job]
    . Isn’t
    Job
    an interface? Why can it be used for indexing? I have checked the source (
    public operator fun <E : Element> get(key: Key<E>): E?
    of
    CoroutineContext
    ) and still don’t have a clue.
    k
    e
    • 3
    • 14
Powered by Linen
Title
c

ckchen

11/03/2018, 12:44 PM
I am learning coroutines and I got confused when I see the code
coroutineContext[Job]
. Isn’t
Job
an interface? Why can it be used for indexing? I have checked the source (
public operator fun <E : Element> get(key: Key<E>): E?
of
CoroutineContext
) and still don’t have a clue.
k

karelpeeters

11/03/2018, 12:49 PM
What happens when you do
Ctrl+B
on
Job
?
c

ckchen

11/03/2018, 12:50 PM
public interface Job : CoroutineContext.Element
I mean,
Job
is an interface, not an instance of
Key<E>
. Why can it be passed to
public operator fun <E : Element> get(key: Key<E>): E
?
k

karelpeeters

11/03/2018, 12:54 PM
Dammit I remember reading about this, I completely forgot though. You might have more luck asking in #coroutines
e

elizarov

11/03/2018, 12:57 PM
It is called companion object.
https://kotlinlang.org/docs/reference/object-declarations.html#companion-objects
k

karelpeeters

11/03/2018, 1:01 PM
Huh might be misremembering then, wasn't there something special about
[Job]
?
c

ckchen

11/03/2018, 1:04 PM
I see this
public companion object Key : CoroutineContext.Key<Job>
in
Job
. So, why not
coroutineContext[Job.Key]
?
e

elizarov

11/03/2018, 1:05 PM
You can use
Job.Key
. But since
Key
is a companion object to
Job
, simply using
Job
works, too.
c

ckchen

11/03/2018, 1:06 PM
Is this a hidden secret? 😀 I don’t see it addressed in the document of companion objects.
k

karelpeeters

11/03/2018, 1:08 PM
They explain it the other way around, first with a custom name and then "you can omit it".
c

ckchen

11/03/2018, 1:11 PM
I know. But I thought they are talking about calling the method of the companion object. I didn’t expect that we can refer to the companion object by omitting it and just use the class name.
e

elizarov

11/03/2018, 3:31 PM
Indeed, it is not explicitly spelled in the docs. It would be nice to add such an example there
c

ckchen

11/04/2018, 12:52 AM
Yes. So I made a simple pull request yesterday (https://github.com/JetBrains/kotlin-web-site/pull/1192). Hope it would be helpful.
View count: 3