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

    Hullaballoonatic

    06/30/2019, 6:44 AM
    I just have never understood the whole OOP vs Functional debate. They're not mutually exclusive. Sure, you can't fully do both at once, but the best principles of each can always be considered. Kotlin definitely pushes for the immutability of data that FP espouses. But even in OOP, it's been established for a long time that it is horrible etiquette to have a function operate on the arguments, unless you absolutely have to (i.e. it would be significantly less efficient not to) Hence why often in oop, a method will return a new instance of a class instead of changing the state of the instance passed in. Essentially, I just think always design your objects to the best principles of oop and your functions to the best principles of functional and why debate?
    👍 2
    👀 2
    m
    c
    +4
    • 7
    • 12
  • m

    Maksim Vlasov

    06/30/2019, 10:18 AM
    Hi! What do you think about ktlint? Do you use it? Does kotlin team have any plans to integrate it in the compiler toolkit, like Go and Rust? Links: https://ktlint.github.io/#getting-started https://golang.org/pkg/go/format/ https://github.com/rust-lang/rustfmt
    t
    g
    d
    • 4
    • 7
  • t

    tschuchort

    06/30/2019, 1:32 PM
    What is the easiest way to create a multimodule project in IntelliJ with all the necessary submodules and subdirectories (src, main, test, kotlin, java, resources)? If I use the convoluted module settings it will take me a whole day to do something that should take 10 seconds at most.
    m
    c
    • 3
    • 7
  • b

    bloder

    06/30/2019, 1:47 PM
    Hi all, is there a more decoupled guard solution planned for Kotlin? I see Elixir`s guard as a good example and it's a solution that I really would like to use, translated to Kotlin is something like:
    fun handleError(e: Exception) if(e is NetworkException) {}
    
    fun handleError(e: Exception) if(e is WrongUserException) {}
    
    fun handleError(e: Exception) if(e is OtherException) {}
    g
    p
    • 3
    • 32
  • v

    ValV

    06/30/2019, 7:47 PM
    Are there some comfortable Kotlin (perhaps, online) decompilers? Java decompilers give something like
    kotlin.jvm.functions.Function0
    ➕ 1
    g
    g
    • 3
    • 14
  • s

    Siddhartha Juluru

    06/30/2019, 10:40 PM
    Could someone explain to me what the suspend keyword does to a function?
    :stackoverflow: 2
    k
    e
    l
    • 4
    • 4
  • j

    Jon

    06/30/2019, 11:06 PM
    I have been trying to find a good static analysis tool for Kotlin and already looked into detekt, ktlint and sonarqube. I learned that intellij has a built-in static analysis tool which can be run from the command line. I am wondering if this will provide similar results to running the inspection from Android Studio
    g
    • 2
    • 1
  • a

    Antanas A.

    07/01/2019, 8:44 AM
    for jvm is ok, how about js and ios/native?
    k
    g
    d
    • 4
    • 12
  • s

    Stephan Schroeder

    07/01/2019, 1:45 PM
    if don’t understand why I have to explicitly do a non-null cast
    if (prioritizedViews != null) {
                prioritizedViews as PrioritizedViews<CareHomeView>
            } else ...
    in
    class CareHomeCombinedView(
        private var prioritizedViews: PrioritizedViews<CareHomeView>? = null
    ) {
    
        private val views: PrioritizedViews<CareHomeView> =
            if (prioritizedViews != null) {
                prioritizedViews as PrioritizedViews<CareHomeView>
            } else {
                PrioritizedViews(              
                )
            }
    }
    
    class PrioritizedViews<T>(
        vararg viewsByPriority: T?
    )
    
    interface CareHomeView {}
    the type inference normally includes the null-check! What is different this time? Here the link to the playground: https://pl.kotl.in/js_ASkwV9
    d
    a
    • 3
    • 3
  • j

    jdemeulenaere

    07/01/2019, 2:30 PM
    Is there any way (annotation, IntelliJ plugin) to restrict the auto completion ? I am trying to build a DSL for an experiment, and I'd like autocompletion to only suggest functions/classes/etc from my DSL package. I think that's something that could be very useful if you are building a DSL for people who are not very familiar with Kotlin at first and don't want to get them overwhelmed when editing files in IntelliJ 🙂
    p
    r
    • 3
    • 3
  • p

    Pere Casafont

    07/01/2019, 4:43 PM
    Does anybody know why there's a warning for inlining functions that don't take lambda parameters? Such as
    inline operator fun Int?.plus(other: Int?) = if (this != null && other != null) {
        this + other
    } else {
        null
    }
    Let's say I want to use this in places that are called millions of times per second. Wouldn't the
    inline
    modifier improve performance there as well?
    k
    • 2
    • 2
  • x

    xenoterracide

    07/01/2019, 4:45 PM
    var objectMapper: ObjectMapper = {
                val mapper = ObjectMapper()
                mapper.registerModules(JavaTimeModule(), KotlinModule())
                mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)
                mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL)
                mapper
            }
    is there a way to do an initialization block kind of like this? just
    init
    ? is there something more per property?
    m
    p
    s
    • 4
    • 13
  • a

    Andrew Gazelka

    07/02/2019, 4:07 AM
    looking for opinions… is Kotlin actually useful for writing JavaScript or does it make more sense at the current point in time to just use plain JS?
    h
    n
    +3
    • 6
    • 5
  • j

    JP Wang

    07/02/2019, 6:22 AM
    You can try to run this code. It’s very confused until I looked at the compiled bytecode
    -.kt
    s
    s
    k
    • 4
    • 10
  • n

    Nir Golan

    07/02/2019, 7:43 AM
    hi all i have a question regarding best practice, memory, and everything you can share on the subject private var lateinit xyz private var xyz : ABC ?= null what is better?
    g
    d
    +2
    • 5
    • 21
  • c

    christophsturm

    07/02/2019, 10:27 AM
    is something like this also coming to the kotlin plugin? https://blog.jetbrains.com/scala/2019/07/02/functional-highlighting-for-functional-programming/#after
    😍 2
    🔥 1
    :yes: 1
    👍 2
    m
    g
    k
    • 4
    • 14
  • u

    U75957

    07/02/2019, 12:20 PM
    I need to overload some stdlib extension. It works, but in some cases show incorrect
    Type missmatch
    until I write all parameters.
    g
    c
    • 3
    • 5
  • v

    victor

    07/02/2019, 12:35 PM
    Is Kotlin going to support Fuchsia? https://fuchsia.dev/fuchsia-src/development/languages/new/structure
    👍 4
    🤣 1
    s
    d
    +2
    • 5
    • 6
  • a

    Adam Hurwitz

    07/02/2019, 5:22 PM
    I'd love feedback on what people think a fair hourly rate is for a mobile developer with 3 yrs experience training a team of developers in Kotlin? It would be for 40 hrs of work a week in a month long gig. Training may include tech talks, writing sample code, and providing code reviews. Most travel expenses will be covered as well. Thus far, I've heard everything from $150 - $250 / hr. Much appreciated! Adam
    p
    m
    • 3
    • 3
  • k

    Krotick

    07/02/2019, 5:31 PM
    Hi! I am using Mockk and I am trying to build a generalized interface. My code:
    interface Captor<T> {
      val captor: CapturingSlot<T>
    }
    Mockk's class deinition:
    class CapturingSlot<T : Any>()
    Yet, I am getting Type argument is not within its bounds. Expected: Any. Found: T Can anyone point me in the right direction?
    s
    • 2
    • 7
  • z

    Zach Klippenstein (he/him) [MOD]

    07/02/2019, 6:14 PM
    Is there any way to clear the session ID/create a new session in play.kotlinlang.org, besides clearing cookies?
    k
    • 2
    • 2
  • a

    Andrew Gazelka

    07/02/2019, 9:43 PM
    Anyone have any idea why this isn’t working? (
    val people = setOf(personA, personC)
    )
    json {
            "test1" to array(personA, personC) //works
            "test2" to array(*people) // does not work
        }
    interface KlaxonJson {
    fun array(vararg args: Any?) : JsonArray<Any?> = JsonArray(args.map { convert(it) })
    // ...
    k
    t
    h
    • 4
    • 8
  • q

    qwert_ukg

    07/03/2019, 4:09 AM
    How to update Kotlin stdlib from 1.2 to 1.3 in IDEA? When i try
    mvn clean install
    i have get an error:
    [ERROR] Failed to execute goal org.jetbrains.kotlin:kotlin-maven-plugin:1.3.31:compile (compile) on project altyn-i-website: Compilation failure: Compilation failure:
    [ERROR] ...Service.kt:[6,22] Unresolved reference: Random
    But i can run my app from IDEA successfully
    i
    • 2
    • 1
  • j

    J. Pablo Fernández

    07/03/2019, 5:42 AM
    Is there a channel here to post about kotlin job opportunities?
    i
    • 2
    • 2
  • k

    Kulwinder Singh

    07/03/2019, 12:37 PM
    is there any better way in kotlin to handle this catch blocks, because in android i am using
    Equalizer
    class, so in Equalizer class most of the getters/setters
    throws
    this 4-5
    exceptions
    . so to access single value i have to add much code
    -.kt
    r
    k
    +4
    • 7
    • 26
  • r

    Rohan Maity

    07/03/2019, 4:43 PM
    Are lambdas faster to execute than normal function in Kotlin ?
    i
    d
    +3
    • 6
    • 8
  • i

    Ifvwm

    07/04/2019, 6:46 AM
    how I can pass my kotlin code to someone's java project?
    r
    u
    n
    • 4
    • 10
  • a

    arekolek

    07/04/2019, 12:24 PM
    inline fun Foo.notMyFunction(block: Bar.() -> Unit) {
        bar.apply(block)
    }
    
    inline fun <R> Foo.myFunction(block: (Bar) -> R): R {
        notMyFunction {
            return let(block)
        }
        error("")
    }
    is there any reasonable way to implement
    myFunction
    given
    notMyFunction
    ?
    m
    d
    k
    • 4
    • 7
  • n

    Nikolay Kasyanov

    07/04/2019, 3:05 PM
    hey folks, is this a known issue/feature?
    kotlin
    fun main(args: Array<String>) {
        whatever(-2)
        whatever(0)
        whatever(2)
    }
    
    fun whatever(input: Int) {
        if (input < 0) {
            "negative"
        } else if (input > 0) {
            "positive"
        } else {
            "zero"
        }.let {
            println(it)
        }
    }
    prints:
    zero
    positive
    r
    p
    +3
    • 6
    • 11
  • l

    LeoColman

    07/04/2019, 3:35 PM
    Do you think it's ok in this case?
    a
    k
    • 3
    • 14
Powered by Linen
Title
l

LeoColman

07/04/2019, 3:35 PM
Do you think it's ok in this case?
a

Adam Powell

07/04/2019, 3:37 PM
Personally I went the other way and started
PascalCasing
my enums instead
precedent here in ktor: https://github.com/ktorio/ktor/blob/master/ktor-http/common/src/io/ktor/http/HttpStatusCode.kt
l

LeoColman

07/04/2019, 3:38 PM
interesting
very interesting actually xD
a

Adam Powell

07/04/2019, 3:44 PM
also other public `val`s for the same reason; when you put them next to `object`s and sealed classes, as you've found, there doesn't seem to be much reason to leak the implementation details in the naming convention
it still seems kind of contentious when it comes to things like
MAX_VALUE
-type things that can be declared with
const val
and the official kotlin style guide is kind of vague on this
https://kotlinlang.org/docs/reference/coding-conventions.html#property-names
it permits both styles but it's not something so prescriptive that you could use linters to settle debates
k

karelpeeters

07/04/2019, 5:04 PM
Same here, PascalCase for most enums.
l

LeoColman

07/04/2019, 9:01 PM
That's very interesting
linters complain about pascal case too, tho
k

karelpeeters

07/04/2019, 9:03 PM
Just turn that off, we're not here to serve the linter!
l

LeoColman

07/04/2019, 9:22 PM
I know hahaha
I just wanted to know if it was a bad thing
View count: 2