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

    ilya.gorbunov

    05/30/2017, 4:05 PM
    var may be a property in the outer scope, you can create local val with the same name
  • a

    aerb

    05/30/2017, 4:08 PM
    @mg6maciej Can you check the state of a
    lateinit var
    ?
    r
    • 2
    • 1
  • p

    pcarrier

    05/30/2017, 4:17 PM
    Toronto hype 😉
    p
    • 2
    • 1
  • v

    voddan

    06/16/2017, 11:21 AM
    This syntax is already in the language if you a willing to prefix your "literal" with a keyword like
    arr["a", "b", "c"]
    (can be implemented via
    get
    http://kotlinlang.org/docs/reference/operator-overloading.html#indexed)
    e
    g
    d
    • 4
    • 8
  • v

    voddan

    06/16/2017, 11:24 AM
    ...Same goes for maps with an addition of a "pairing keyword"
    map {1 + "1"}
    (this can be done without generating intermediate objects like pairs)
    m
    • 2
    • 3
  • m

    miha-x64

    06/16/2017, 11:25 AM
    Also, it’s possible to create a DSL-style map generator, e. g.
    map {
        + "k" to "v"
    }
    v
    • 2
    • 3
  • m

    miha-x64

    06/16/2017, 11:31 AM
    Nothing to propose, 🚙 #random
    j
    • 2
    • 1
  • s

    smcvb

    06/16/2017, 2:16 PM
    I've got a question concerning inheriting from an abstract class on a data class. Let say we have the following abstract class:
    abstract class AbstractExample(
        open val paramOne: Int,
        open val paramTwo: String
    )
    And, the following implementation of the example abstract class:
    data class ExampleImpl(
            override val paramOne: Int,
            override val paramTwo: String,
            val paramThree: Boolean
    ) : AbstractExample(paramOne, paramTwo)
    I have to override
    paramOne
    and
    paramTwo
    , because of the following message I get: 'Data class primary constructor must have only property (val / var) parameters' I'd ideally however have an
    ExampeImpl
    like so:
    data class ExampleImpl(
            paramOne: Int,
            paramTwo: String,
            val paramThree: Boolean
    ) : AbstractExample(paramOne, paramTwo)
    Or this at least looks cleaner to me, since this doesn't mean I need to instantiate
    paramOne
    and
    paramTwo
    for
    ExampleImpl
    again and thus use the variables and getter/setter from the
    AbstractExample
    as I'd prefer to. As far as I know this currently isn't a possibility, hence I dropped in this channel.
    k
    • 2
    • 3
  • g

    groostav

    06/26/2017, 5:48 PM
    so me and a cofounder just spent 10 minutes running down an exception that boils down to a "key not in map exception". One reason is because a junior dev was suppressing the exception, but another reason is because when business rules dictate that a map will contain your key, we simply write
    map[key]!!
    . I suppose this is our mistake and we should instead write
    map[key] ?: keyNotFound(map, key)
    but that's clunkey. Could write an extension function but that means we loose the slick square-brackets syntax, and its though to make idioms without them being part of the standard-lib.
    i
    p
    • 3
    • 6
  • b

    bmo

    07/11/2017, 8:29 AM
    It's not for testing, I'm an android developer and it happens fairly often that we have to implement interfaces only to override one method which brings lots of boilerplate code
    m
    s
    • 3
    • 6
  • p

    programmerr47

    07/14/2017, 6:04 AM
    Hey all. Recently I've created stackoverflow question and then question in kotlin forum about BigDecimal progressions. Here is a link to it: https://discuss.kotlinlang.org/t/kotlin-bigdecimal-progression/3654 In short: kotlin has a progressions. In fact it has Char, Int and Long progressions. One of the sugar things that language supports to them is '..' operations. So you able to write something like (0..10) or (0L..10L) or ('a'..'z'). My question is can it be done for BigDecimals? So I wrote simple implementation of it (based on IntProgression), you can find it in the above link. But main problem is, when you implementing your own progression you not able to write (bigDecimal1..bigDecimal2) since there is no support '..' for BigDecimals. So my question is, can we really implement ranges and progressions for BigDecimals? And if yes, then my proposal is to do it. Thank you. Will appreciate to see feedback.
    g
    • 2
    • 6
  • d

    damian

    07/20/2017, 4:59 PM
    On the topic of inline functions which return function types: Is it possible/realistic to have an optimization which inlines a return value if it is either: - A: invoked immediately, or - B: passed as an argument to another inline function ... but is not stored in a variable? E.g.
    inline val fooFunction: () -> Unit
      get() = { println("hello world") }
    
    fun bar() {
      fooFunction() // immediate invocation results in complete inlining of "println" body
    }
    I think this is a pretty obscure use case, but could see it being beneficial for something like funKTionale (using partial application, etc)
    🤔 1
    d
    • 2
    • 1
  • k

    kirillrakhman

    07/21/2017, 1:51 PM
    c# actually has that https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/operators/null-conditional-operators
    👍 2
    e
    • 2
    • 2
  • v

    voddan

    07/27/2017, 10:12 AM
    Also, in Swift:
    var list1 = [1, 2] //mutable
    let list2 = [3, 4]  // immutable list
    This is the difference between JVM's reference semantic and Swift's struct/class semantics. It is a fundamental difference in the platforms.
    b
    • 2
    • 1
  • b

    benleggiero

    07/27/2017, 12:07 PM
    If you have a large array named
    foo
    (let's say it's 1GB) and then you say
    var bar = foo
    , a "copy" is made, yes. And I'm not 100% sure how, but no delay is incurred. I suspect that you get a new pointer, and any changes you make are reflected as diffs. Also,
    let foo = "foo"; let bar = foo
    , IIRC, makes
    foo
    and
    bar
    point to the same memory, which is safe because neither can be mutated.
    v
    • 2
    • 3
  • d

    dmitry.petrov

    07/27/2017, 5:12 PM
    There're several possible ways to mitigate this issue, e.g., "this method is available in specializations where type argument
    T
    is a reference type (or: is a primitive type)".
    b
    • 2
    • 2
  • k

    karelpeeters

    07/30/2017, 7:05 PM
    @benleggiero That would break encapsulation, no?
    b
    r
    • 3
    • 4
  • j

    joelpedraza

    08/02/2017, 5:25 PM
    I was surprised to find Kt does not have null safe index operators arr?[i]. They would be especially useful for traversing nested structures. The closest issue I could find was https://youtrack.jetbrains.com/issue/KT-19168. Its still in the Submitted state. Here's what they look like in C#
    t
    v
    r
    • 4
    • 3
  • k

    kirillrakhman

    08/02/2017, 8:43 PM
    I've submitted https://youtrack.jetbrains.com/issue/KT-19444 (Add JVM-specific annotation to permit accidental overrides). What do you guys think about it? I have two concrete issues in my mind this would solve: letting enums implement interfaces and letting properties implement java interfaces with getters
    ➕ 1
    b
    • 2
    • 1
  • k

    karelpeeters

    08/02/2017, 11:24 PM
    @benleggiero Let's say an object has some hidden state, ie. it doesn't expose a getter and setter for one of its fields. Then I could just come along and write an extention function to read and modify that previously hidden state. See how this doesn't work in practice?
    b
    • 2
    • 1
  • d

    dmitry.petrov

    08/03/2017, 8:38 AM
    Rather in-depth technical talk about value types in JVM (for those who care):

    https://www.youtube.com/watch?v=xyOLHcEuhHY▾

    Programming with Minimal Values Maurizio Cimadamore, JVM LS 2017
    🤔 2
    • 1
    • 1
  • j

    jlleitschuh

    08/04/2017, 6:04 PM
    I looked in the KEEP project and the Kotlin youtrack and didn't see anything about this so I figure I'd propose it here: The current implementation of data classes is really nice, however, creating large data classes can end up creating large constructors. I really like them because they create nicely immutable bundles of data. In java, the builder pattern is usually utilized when constructors start to get large. However, the builder pattern can become quite clunky quickly, even when written by hand in kotlin. A developer could use the google auto-value annotation processor but I don't think this works with data classes. Plus its clunky and you have to deal with IDE configuration. In kotlin named parameters gets around this issue quite nicely because you can selectively specify the fields you want to assign. However, when creating a new instance of a data class in Java you end up with a very large constructor call without any way of knowing what fields you are assigning in the object when looking at the constructor. My proposal is that data classes get expanded to have a static
    builder()
    method on them that allows data classes created from java to use this builder. Default values that the data classes already have wouldn't be required to be specified in the builder. What are peoples thoughts on this? I'll open an issue in project KEEP if this is worthy of more feedback.
    👍 2
    e
    v
    • 3
    • 18
  • r

    raulraja

    08/11/2017, 7:59 PM
    @dmitry.petrov do you know if there are any examples of that out there? I'd love to check it out.
    d
    • 2
    • 11
  • d

    dean

    08/12/2017, 5:29 AM
    They're discouraged in Golang anyway, I was just trying to think of something new 😅
    👌 1
    p
    • 2
    • 1
  • r

    raulraja

    08/12/2017, 7:34 PM
    @dmitry.petrov Do you know if the Kotlin compiler is threadsafe? Meaning, can I invoke it in parallel and let it be safe? Asking because the Scala one for example is not and what I'm doing is evaluating N snippets of code in the fly whose evaluation does not depend on each others results.
    y
    • 2
    • 2
  • j

    jimn

    08/14/2017, 6:22 AM
    i have done this in java with bytebuffers in the past, with limitted success, but a dancing bear isn't amazing because of the skill with which it dances...
    o
    • 2
    • 1
  • d

    dmitry.petrov

    08/14/2017, 9:01 AM
    We have another solution on the table:
    x
    in
    x as T
    should be resolved with an expected type T. So, code like
    findViewById(...) as MyView
    would work as it did before.
    r
    • 2
    • 3
  • j

    jw

    08/14/2017, 3:10 PM
    The contract didn't break, that's the point
    r
    • 2
    • 5
  • s

    Slackbot

    08/15/2017, 6:41 PM
    This message was deleted.
    k
    k
    • 3
    • 2
  • g

    gabrielfv

    08/15/2017, 8:02 PM
    what you guys think about nullable parameters defaulting to null?
    fun foo(bar: Int?)
    can be called like
    foo()
    , instead of having to write
    fun foo(bar: Int? = null)
    . I see people comonly reading the
    ?
    as sort of "opitional" in this context, and I don't see the point of calling
    foo(null)
    , though makes some sense when
    val a: Int? = mayReturnInt()
    foo(a)
    which is also a common scenario
    ➖ 10
    👍 1
    u
    b
    • 3
    • 10
Powered by Linen
Title
g

gabrielfv

08/15/2017, 8:02 PM
what you guys think about nullable parameters defaulting to null?
fun foo(bar: Int?)
can be called like
foo()
, instead of having to write
fun foo(bar: Int? = null)
. I see people comonly reading the
?
as sort of "opitional" in this context, and I don't see the point of calling
foo(null)
, though makes some sense when
val a: Int? = mayReturnInt()
foo(a)
which is also a common scenario
➖ 10
👍 1
u

umar

08/15/2017, 9:36 PM
There are few cases you really need nullable types, so being explicit achieves two goals: you can see that here is default argument and it is null, and code will be consistent for nullable and nonnullable types.
☝️ 2
g

gabrielfv

08/15/2017, 9:40 PM
I see those cases. I see that there would be consistence between types given that when they have the
?
operator they could be
null
by default, and there'd be no other possibility for a default value, unlike 0 for
Int
or
""
for
String
.
Having types not null by default and depending on an attention raising operator like
?
makes it very clear that a value can be null. That's it's role after all.
It also doesn't break consistency with non-null parameters, since
fun foo(a: Int? = 0)
can accept
foo(null)
, with
a
actually being
null
and
foo()
with
a
being
0
.
The other side, the scenario where
fun foo(bar: Int)
would not be passive of being called
foo()
and would break is not a different behavior, but could be due to the fact that
bar
could not be null and therefore there is no way to infer anything.
b

benleggiero

08/16/2017, 1:53 AM
Too confusing. Looks like
?
means "optional parameter", not "nullable and optional". I can imagine newcomers thinking that Kotlin only allows omitted optional parameters to be null and not bothering to discover the
=
syntax
This would also break any APIs where the designer wanted the developer to be explicit about whether something's null
g

gabrielfv

08/16/2017, 4:50 AM
I don't see what you mean in this last message, @benleggiero
APIs that wanted the user to call a method like
foo(null)
explicitly? Is there any example?
u

umar

08/16/2017, 6:07 AM
Can you get with use case, where you need so many `nullable`s, and their default must be
null
?
View count: 3