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

    Ben Dodson

    05/15/2019, 4:54 PM
    I saw this mentioned in another channel but not discussed here-- Lambdas that disallow capture. Use
    {{}}
    instead of `{}`:
    chain.map{{ input -> /* capture throws a compiler error */ }}
    👍 3
    🤔 3
    e
    d
    +4
    • 7
    • 11
  • l

    littlelightcz

    05/19/2019, 6:57 PM
    Are there any plans for adding a 'mutableIncrement' operator? Because right now I am not able to write my own extension function for this use case that would behave like this:
    val foo = AtomicInteger(0)
    foo++
    Current
    increment
    operator would allow me to work only with
    var foo
    , but this is obviously not what I want. In my use case I want to launch N coroutines and show a progress bar with how many of them have already finished (tracked in the
    foo
    AtomicInteger)
    m
    r
    e
    • 4
    • 14
  • m

    Martin Devillers

    05/21/2019, 12:52 PM
    Here’s a strange case that I just ran into. Even though the language forbids overriding inline methods, it’s actually possible here. The method signatures differ by the input lambda type, which is erased at runtime, and by the return type.
    -.kt
    m
    i
    d
    • 4
    • 11
  • m

    Marc Knaup

    05/30/2019, 3:35 PM
    Idea: Passing an array to a
    vararg
    parameter using
    vararg
    keyword. Reason: Make code easier to read & understand (one keyword in both locations), simplify language (no extra unary
    *
    operator needed) Esp. helpful for people who are new to Kotlin or have only rarely if ever use spread operators in other languages. Example:
    ByteString.of(*buffer.toByteArray())
    ->
    ByteString.of(vararg buffer.toByteArray())
    At the declaration-site
    vararg
    denotes "variadic number of parameters". At the call-site
    vararg
    denotes "variadic number of arguments".
    ➕ 3
    ➖ 9
    p
    p
    +2
    • 5
    • 7
  • m

    Marc Knaup

    06/06/2019, 3:28 PM
    I see myself using
    data class
    a lot - but mostly for automatically generating
    toString()
    and
    equals()
    , sometimes
    hashCode()
    , rarely `copy`(). I never care about
    componentX()
    for destructuring but noticed that their existence can be confusing to people (and me changing the order of properties breaking their code). The general idea of having less boilerplate for simple repetitive tasks / common idioms is good. It would be awesome if developers could express with more detail what auto-generated functionality is actually desired and which is not. This also makes the actual capabilities and the intended usage of a class clearer than using a
    data class
    that adds functionality which may not always make sense. I know that I may be misusing data classes here and I guess I'm not the only one using them to avoid manual and repetitive implementation of
    toString()
    ,
    equals()
    and
    hashCode()
    . In addition to having less boilerplate the compiler can generate well-optimized implementations which are even more work & code when done manually (think for example a good
    hashCode()
    implementation over multiple properties without boxing or platform dependency à la Java's
    Objects.hashCode(…)
    ). I like Swift's approach where a developer can for example state that a
    struct
    is
    Equatable
    or even
    Hashable
    and if all properties are too then the implementation is auto-generated by the compiler. Kotlin could do the same to make adding these method simpler. E.g. if I add
    : AutoEquatable
    to a class the compiler could auto-generate
    equals()
    for me over all properties - just like a data class and potentially using the same constraints as for these. Same for
    AutoHashable
    ->
    hashCode()
    ,
    AutoStringConvertible
    (or alike) ->
    toString()
    ,
    AutoCopyable
    ->
    copy()
    and
    AutoDestructurable
    ->
    componentX()
    . A
    data class
    is automatically
    AutoEquatable
    ,
    AutoCopyable
    ,
    AutoDestructurable
    ,
    AutoHashable
    and
    AutoStringConvertible
    . @gildor suggested to use annotations instead of interfaces, which is also a good option. There would be no need to change the language itself. The Standard Library would merely add a few interfaces and the compiler use them for auto-generating some code. Another alternative could be to use data classes but opt out to some of its functionality, e.g.
    data(nocopy, nocomponents) class …
    . That would require syntax and language changes though. What do you think? 🤔
    o
    i
    +6
    • 9
    • 114
  • q

    Quy D X Nguyen

    06/08/2019, 2:27 AM
    Any reason why users of inline classes cannot use @PublishedApi internal constructors? I see them in the Result<T> KEEP and I think "forcing" Kotlin users to use a factory function to get an instance has many use cases. Currently I've resorted to just marking the constructor deprecated and hoping users don't use it/
    l
    m
    • 3
    • 4
  • h

    Hullaballoonatic

    06/10/2019, 7:58 PM
    Annotations that set a default function for overload ambiguity
    @AmbiguityDefault
    operator fun Foo.plusAssign(other: Foo)
    f
    d
    • 3
    • 5
  • h

    Hullaballoonatic

    06/11/2019, 7:50 PM
    fun repeatReversed(times: Int, action: (Int) -> Unit)
    in stdlib?
    ➖ 2
    m
    p
    • 3
    • 6
  • r

    Ruckus

    06/13/2019, 8:50 PM
    Proposal: Allow
    inner object
    On several instances I've come across a situation where I have code like:
    class Parent {
        val child: Child = Child()
    
        inner class Child
    }
    Where it would be preferable to have:
    class Parent {
        inner object Child
    }
    The main advantage I'm looking for (other than readability) is locality: - Every
    Parent
    has in instance of
    Child
    -
    Child
    is a well defined type - You cannot create new instances of
    Child
    with something like
    parent.Child()
    👍 9
    s
    k
    h
    • 4
    • 8
  • h

    Hullaballoonatic

    06/14/2019, 9:41 PM
    try {
        ...
    } catch { e ->
        ...
    }
    try foo() catch { bar(it) }
    try foo() catch bar()
    or as @Marc Knaup suggested:
    try foo() else bar()
    instead of
    catch
    in the event you are ignoring the throwable
    m
    o
    +3
    • 6
    • 34
  • h

    Hullaballoonatic

    06/15/2019, 11:27 PM
    a way to place inner classes or functions thereof in a different file for better organization, potentially via annotations:
    import foo.Foo
    @innerOf(Foo)
    inner class Bar
    import foo.Foo
    @innerOf(Foo.Bar)
    fun bar() = "blah"
    The same may then be extended to sealed classes
    ➖ 7
    g
    • 2
    • 1
  • w

    wickedev

    06/16/2019, 2:10 PM
    I’ve found these syntaxes in Google’s Android repository. Is this a valid syntax? Or is there a possibility in the future?
    <SemanticsComponentNode
        container
        explicitChildNodes
        enabled
        checked
        selected
        button
        header=null
        textField=null
        focused=null
        inMutuallyExclusiveGroup
        obscured=null
        scopesRoute=null
        namesRoute=null
        hidden
        label
        value
        hint=null
        textDirection
        testTag=(testTag ?: providedTestTag)
        actions>
        TestTag(tag=DefaultTestTag) {
            children()
        }
    </SemanticsComponentNode>
    https://android.googlesource.com/platform/frameworks/support/+/refs/heads/androidx-master-dev/ui/framework/src/main/java/androidx/ui/core/Semantics.kt#130
    k
    • 2
    • 7
  • n

    Nicole

    06/19/2019, 12:43 AM
    Idea: JVM getter name change. Currently:
    data class Component(val active: Boolean) {
        val getList get() = listOf("empty")
        val isPoorlyNamed get() = 10
        val isCorrectlyNamed get() = true
    }
    JVM code:
    Component component = new Component(false);
    component.getActive();
    component.getGetList();
    component.isPoorlyNamed();
    component.isCorrectlyNamed();
    Proposal: To better match Java Bean naming conventions:
    val active
    ->
    boolean isActive()
    - Boolean return maps to “isProperty”
    val getList
    ->
    List<String> getList()
    - Already prefixed with “get” -> leave it
    val isPoorlyNamed
    ->
    int getIsPoorlyNamed()
    - Prefixed with “is”, but isn’t a boolean -> add “get” prefix
    val isCorrectlyNamed
    ->
    boolean isCorrectlyNamed()
    - Same as today
    👎 3
    👍🏼 1
    g
    k
    +3
    • 6
    • 12
  • j

    jdemeulenaere

    06/20/2019, 11:12 AM
    Is there any ongoing work on the Result type to make it more available (without the current restrictions) ? I'm also mostly interested in having Result with the languages improvements mentioned in the "integration into the language" section (https://github.com/Kotlin/KEEP/blob/master/proposals/stdlib/result.md#integration-into-the-language)
    r
    b
    +2
    • 5
    • 5
  • h

    Hullaballoonatic

    06/20/2019, 6:38 PM
    a way for interfaces and superclasses to define that an inheritor must have static members of its own of some type. AKA you have to have an object that extends as such
    d
    r
    • 3
    • 4
  • a

    Alexander Vtyurin

    06/26/2019, 7:27 PM
    Proposal: make
    suspendCancelableCoroutine
    a part of the language instead of
    suspendCoroutine
    as a more general and tweakable language unit.
    ➕ 1
    😒uspend: 2
    e
    l
    +3
    • 6
    • 75
  • h

    Hullaballoonatic

    07/02/2019, 9:52 PM
    Replace
    where
    syntax current:
    class Foo<A, B>(val a: A, val b: B) where A: Bar, A: Baz
    proposed:
    class Foo<A: Bar & Baz, B>(val a: A, val b: B)
    not like
    &
    is getting any use in Kotlin anyhow...
    ➕ 4
    k
    k
    • 3
    • 4
  • h

    Hullaballoonatic

    07/02/2019, 10:07 PM
    Oh boy, multiple inheritance! Already "achievable" like so:
    interface Bar {
        val bar: Int
        companion object {
            operator fun invoke(bar: Int) = object : Bar {
                override val bar = bar
            }
        }
    }
    
    interface Baz { 
        ...same as how Bar is implemented 
    }
    
    class Foo(bar: Int, baz: Int): Bar by Bar(bar), Baz by Baz(baz)
    but wouldn't it be nice to just:
    class Foo(bar: Int, baz: Int): Bar(bar), Baz(baz)
    ➖ 5
    r
    g
    j
    • 4
    • 16
  • h

    Hullaballoonatic

    07/03/2019, 12:22 AM
    Reference properties using
    by
    ,
    is
    , or something like that current:
    var foo = 3
    
    var bar
        get() = foo
        set(v) {
            foo = v
        }
    proposed:
    var foo = 3
    var bar by foo
    ➕ 3
    ➖ 1
    d
    i
    +2
    • 5
    • 8
  • d

    diego-gomez-olvera

    07/08/2019, 10:36 AM
    I created an issue for a potential optimization: It seems that when there is a method with
    vararg
    and 0 arguments, a
    new Object[0]
    is allocated every time, according to the decompiled code https://youtrack.jetbrains.com/issue/KT-32474
    g
    k
    • 3
    • 4
  • r

    Ruckus

    07/12/2019, 2:39 PM
    Proposal: apply operator I find myself often in the situation where I create a new thing and have to call a single method on it as part of setting it up. The common form is to use
    val thing = Thing().apply { setup(...) }
    . While this is simple enough, I do it so often it would be nice to have an operator for it, that calls the function, but ignored the return value and returns the receiver instead, so I could do something like
    val thing = Thing()&.setup(...)
    This may just be to my style of programming, but I figured I'd throw it out there to see if anyone else is interested.
    ➖ 5
    ➕ 1
    d
    k
    +4
    • 7
    • 16
  • h

    Hullaballoonatic

    07/12/2019, 8:21 PM
    foo if (condition)
    syntax, like exists in Ruby and other languages. It is superior to
    if (condition) foo
    in that it doesn't allow for multiline, and avoids the problem of:
    if (foo)
        bar
        baz // not in scope
    Also maybe drop the condition's enclosing
    ()
    ➖ 6
    l
    j
    +3
    • 6
    • 8
  • j

    jdemeulenaere

    07/18/2019, 3:19 PM
    Proposal: Add InvocationKind.LAZY to contracts to specify that a lambda parameter will not be called before its declared method has returned. Use case: See sample code at https://pastebin.com/8TFJH437
    d
    k
    • 3
    • 3
  • s

    Slackbot

    07/19/2019, 6:23 PM
    This message was deleted.
    h
    j
    • 3
    • 11
  • m

    Muneebshere

    08/08/2019, 10:49 AM
    Can generic parameters be reified at class level? https://discuss.kotlinlang.org/t/can-generic-parameters-be-reified-at-class-level/13791
    d
    s
    r
    • 4
    • 13
  • f

    Fudge

    08/11/2019, 8:17 AM
    Type inference for function argument with default value.
    // Inferred as x: String, y: Int = 2, z : String = "hello"
    fun foo(x : String, y = 2, z = "hello"){
    }
    ➖ 5
    g
    l
    h
    • 4
    • 6
  • d

    david-wg2

    08/13/2019, 9:48 AM
    would be nice if range checks caused smart casting:
    if (pin?.length != 36) throw Exception()
    // pin is smart cast here
    if (pin?.length !in (8..36)) throw Exception()
    // pin is not smart cast here
    d
    d
    • 3
    • 7
  • e

    elect

    08/15/2019, 9:05 AM
    sometimes I wish I could destructuring directly to existing `var`s
    var hovered = false
    var held = false
    if(..) {
        val (_, ho, he) = buttonBehavior(columnHitRect, columnId)
        hovered = ho
        held = he
    }
    ➕ 4
    s
    d
    h
    • 4
    • 11
  • e

    Elijah Verdoorn

    08/20/2019, 7:01 PM
    Idea that myself and @Charles have been discussing: a new keyword on function definition to automatically make the first operation of said function be a call to
    super
    . For example:
    override fun onDestroy() {
        super.onDestroy()
        channel.close()
    }
    could become
    super fun onDestroy() = channel.close()
    The
    override
    word becomes optional, since the call to
    super
    only makes sense in the context of functions that are being overridden.
    👍 2
    ➕ 1
    z
    l
    +5
    • 8
    • 13
  • t

    themarketka

    08/22/2019, 10:44 PM
    Did some digging and discovered https://youtrack.jetbrains.com/issue/KT-22505 about support for treating constant raw strings with
    .trimMargin()
    as `const`s – any chance it would get done in some reasonably near future? I’d offer myself to implement a PR for the compiler if only I had better understanding of it. :kotlin-flag:🐿🎄
    r
    • 2
    • 1
Powered by Linen
Title
t

themarketka

08/22/2019, 10:44 PM
Did some digging and discovered https://youtrack.jetbrains.com/issue/KT-22505 about support for treating constant raw strings with
.trimMargin()
as `const`s – any chance it would get done in some reasonably near future? I’d offer myself to implement a PR for the compiler if only I had better understanding of it. :kotlin-flag:🐿🎄
r

Ruckus

08/23/2019, 1:36 PM
Please note the channel topic:
All discussion in this channel should begin with a use-case or proposal instead of a question.
This isn't the channel to ask about progress on issues.
View count: 2