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
language-proposals
  • i

    igor.wojda

    01/27/2017, 11:17 AM
    Is there any particular technical reason why it is not possible to use
    lateinit
    with immutable (val) properties or is it just deliberty forced limitation? I wonder becouse this limitation does not allow to define non nullable variable that will be initialized latter only once. Now we can only have mutable injected variables witch can be latter changed by accident (val + lateinit would solve this issue) Now:
    @Inject lateinit var repository: Repository
    Want:
    @Inject lateinit val repository: Repository
    //initialization is delayed but it is still possible assign value only once
    r
    • 2
    • 1
  • c

    cedric

    02/01/2017, 3:06 PM
    +1 to @mg6maciej .
    varargs
    with size seems pretty obscure for deserving a language construct. Leave that at runtime.
    ➕ 2
    g
    • 2
    • 3
  • b

    benleggiero

    02/02/2017, 1:30 AM
    @ilya.gorbunov how is it any more difficult than
    fun Array<*>.myInterfaceFunction() {}
    ?
    i
    • 2
    • 8
  • e

    elect

    02/03/2017, 8:10 AM
    []
    operator on `Buffer`s?
    e
    d
    • 3
    • 16
  • z

    zokipirlo

    02/03/2017, 8:24 AM
    is there any plan to support functions like defer, throttle and debounce (http://underscorejs.org/#defer)? maybe is this a better question for anko? i know that they exists in rx but kotlin already supports a lot of things from rx and i don’t know if it makes any sense to include whole library just for this.
    e
    • 2
    • 5
  • a

    aimozg

    02/04/2017, 9:16 PM
    ...using
    let
    ,
    apply
    etc always make feel uncomfortable and I just have to double check it has
    @InlineOnly inline /* don't worry it won't create anonymous class filled with reflection*/ fun
    signature...
    m
    • 2
    • 5
  • a

    aimozg

    02/07/2017, 4:14 PM
    attachments.fold(attachments as Collection<String>?){ arr, it -> if (it == null) null else arr }
    😱 1
    • 1
    • 1
  • v

    voddan

    02/07/2017, 6:52 PM
    My 5 cents: #general at the moment works as a dispatcher channel where people write when they are not sure what would be the appropriate channel for their post. After that discussions very often jumps into #getting-started, #android, #javascript, etc.
    r
    • 2
    • 2
  • v

    voddan

    02/07/2017, 7:55 PM
    @orangy Their theme is the same (general questions), but in #general one has a much higher chance to be sent to Google or SO, while in #getting-started people tend to answer even the most basic questions
    • 1
    • 1
  • b

    benleggiero

    02/07/2017, 8:49 PM
    I also just had this idea:
    for (x in y) {
        // Code that might break
    } else if break {
        // If the loop exited via a break
    } else if !break {
        // If the loop exited normally (no break)
    } else {
        // If the loop was never entered
    }
    😈 1
    🙈 2
    m
    a
    j
    • 4
    • 8
  • o

    orangy

    02/07/2017, 9:24 PM
    Take for example interface delegation feature in Kotlin. I personally think it was a mistake to put it in a language, though it is extremely useful at times.
    r
    m
    c
    • 4
    • 10
  • g

    groostav

    02/10/2017, 10:36 PM
    the
    where
    function would take an AST representation of the body --effectively it takes source code, and then transcompiles the AST for
    it.name == "bob"
    into
    WHERE c.name == bob
    , of the equivalent mongo thing (iirc something resembling
    {"where" { eq { field { "fname" }, "bob" }}
    a
    • 2
    • 32
  • g

    groostav

    02/10/2017, 10:50 PM
    how can i change those priorities?
    💰 1
    m
    • 2
    • 3
  • a

    aimozg

    02/10/2017, 11:41 PM
    You see, the only purpose of overloaded
    +
    is "shortest way to call an extension function in a context"
    r
    • 2
    • 6
  • d

    dmitry.petrov

    02/13/2017, 10:08 AM
    Probably worst example of operator overloading I had was in some Agda-esque code that used Chinese hieroglyphs.
    🇨🇳 1
    😱 2
    a
    • 2
    • 1
  • b

    benleggiero

    02/13/2017, 2:58 PM
    I prefer this syntax:
    public private(set) var a
    m
    • 2
    • 7
  • g

    groostav

    02/15/2017, 6:50 PM
    yeah @mg6maciej, exactly, I want this in kotlin
    m
    e
    • 3
    • 7
  • s

    sksk

    02/19/2017, 8:30 PM
    what do you guys think about
    partial class
    in C# ?
    👍 3
    b
    p
    • 3
    • 3
  • b

    benleggiero

    02/26/2017, 9:24 PM
    when
    should know when it's been exhaustive if it's evaluating a `sealed class`'s
    KClass
    . For instance:
    sealed class MySealedClass {
        class SubclassA: MySealedClass()
        class SubclassB(val date: Date): MySealedClass()
    }
    
    fun makeInstance(sealedClass: KClass<MySealedClass>): MySealedClass
        = when (sealedClass) {
            SubclassA::class -> SubclassA()
            SubclassB::class -> SubclassB(Date())
        }
    Error:
    Kotlin: 'when' expression must be exhaustive, add necessary 'else' branch
    o
    • 2
    • 2
  • k

    kevinmost

    03/03/2017, 6:59 PM
    I'm so happy it's gone. If your line is that long that the
    if
    and
    else
    vs
    ?
    and
    :
    make it "unreadable", it's probably the code itself that needs to be fixed
  • b

    benleggiero

    03/07/2017, 2:14 AM
    it should be possible to add static extension functions to external classes that have no companion object (like Java objects). Use case:
    fun java.awt.Color.Companion.fromHex(hexString: String): Color {
        ...
    }
    
    ...
    
    val c = Color.fromHex("#123456")
    👍 5
    • 1
    • 1
  • d

    dmitry.petrov

    03/07/2017, 10:04 AM
    https://youtrack.jetbrains.com/issue/KT-16701
    👍 5
    👎 2
    b
    • 2
    • 1
  • d

    dmitry.petrov

    03/09/2017, 2:51 PM
    Something like (with "variable declaration in when subject" as a not-implemented yet secret sauce):
    when (val str = ...) {
      "foo" -> foo()
      if str.contains("bar") -> bar()
      if "baz" in str -> baz()
    }
    👍 1
    v
    • 2
    • 3
  • b

    benleggiero

    03/09/2017, 3:28 PM
    One of the things I love most about Swift is that when it makes breaking changes, those also come with a migration tool that will apply code fixes to reflect those changes. Maybe Kotlin could do the same, especially with things like the IDEA Kotlin plugin
    v
    • 2
    • 1
  • d

    damian

    03/09/2017, 8:45 PM
    There is an issue for it: https://youtrack.jetbrains.com/issue/KT-10468
    m
    • 2
    • 1
  • d

    damian

    03/09/2017, 8:53 PM
    i'd mention in #anko about the @Deprecated
    m
    • 2
    • 1
  • b

    benleggiero

    03/10/2017, 9:02 PM
    If Kotlin for JVM, JS, and Native are to coexist happily, we're gonna need conditional compiler commands like
    #if(JS)
    v
    p
    b
    • 4
    • 15
  • m

    miha-x64

    03/14/2017, 9:16 AM
    Why doesn’t
    kotlin.Enum.Companion
    contain a mapping to
    java.lang.Enum.valueOf()
    ? Also, what about adding
    fun <T : Enum<T>> valuesOf(klass: KClass<T>): Array<T> = klass.java.enumConstants
    ?
    👍 1
    u
    b
    • 3
    • 3
  • k

    kingsley

    03/14/2017, 9:46 AM
    @miha-x64 These 2 functions are available since KT1.1
    fun <reified T : Enum<T>> enumValues(): Array<T>
    
    and
    
    fun <reified T : Enum<T>> enumValueOf(name: String): T
    👍 2
    d
    • 2
    • 1
  • l

    louiscad

    03/16/2017, 2:33 PM
    @benleggiero I thought about this, but this is 4 lines versus two lines for the "ugly" approach
    b
    • 2
    • 2
Powered by Linen
Title
l

louiscad

03/16/2017, 2:33 PM
@benleggiero I thought about this, but this is 4 lines versus two lines for the "ugly" approach
b

benleggiero

03/16/2017, 2:50 PM
fun BluetoothAdapter.isOffOrTurningOff(): Boolean = when (state) {
        BluetoothAdapter.STATE_OFF, BluetoothAdapter.STATE_TURNING_OFF -> true
        else -> false
    }
l

louiscad

03/16/2017, 2:53 PM
Yep, better, but still one extra line 😉 I think I'll stick with the ugly approach until Kotlin comes with a better syntax. For longer lines though, the when statement is my choice #1 too 😉
View count: 2