https://kotlinlang.org logo
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
  • i

    Ifvwm

    07/18/2019, 5:04 AM
    this code is converted by intellij idea, I don't understand why it tonvert a f(a,b) in java to f(a)(b) in kotlin, auto currying? https://paste.ubuntu.com/p/NNbRwmR4mG/
    t
    s
    • 3
    • 66
  • k

    Krzysztof Kocel

    07/18/2019, 9:14 AM
    I have an object:
    class User {
          var id: String? = null
          var name: String? = null
        }
    and list of pairs:
    val fieldsToChange = listOf<Pair<String, String>>(Pair("name", "foo"), Pair("id", "bar"))
    I would like to iterate trough list of pairs and set appropriate values for given properties using reflection. How I can achieve this using kotlin reflection?
    k
    d
    k
    • 4
    • 4
  • a

    aaverin

    07/18/2019, 10:54 AM
    I would love to see classes diagram of my project, to analyse architecture and dependencies between packages. Is there any tool I could use? Built-in Idea Ultimate diagram builder doesn’t seem to work with Kotlin
    t
    c
    • 3
    • 7
  • t

    thiagoretondar

    07/18/2019, 12:35 PM
    What’s the best approach to call a method after all
    Jobs
    stored in a
    List<Job>
    are completed?
    s
    k
    a
    • 4
    • 13
  • l

    Liam Humphreys

    07/18/2019, 1:02 PM
    hey Kotlineers, I've started a Kotlin prettier plugin https://github.com/Angry-Potato/prettier-plugin-kotlin, it's pretty simple and barebones so far, I'd love some more eyes on it if anyone else out there likes Prettier and wants to help bring it to Kotlin!
    l
    • 2
    • 2
  • r

    rrader

    07/18/2019, 7:50 PM
    Is the such library as https://gatling.io/ in Kotlin?
    f
    • 2
    • 1
  • m

    mathew murphy

    07/18/2019, 9:06 PM
    Oh dear, Set.filter() returns a List rather than a Set.
    c
    k
    l
    • 4
    • 8
  • i

    Ifvwm

    07/19/2019, 2:32 AM
    EventCallback<Float> { if (it > 0) println("ouch!") else println("1") } I don't understand the syntax, put a type before a lambda, is ?
    s
    • 2
    • 36
  • a

    Andrew Gazelka

    07/19/2019, 5:40 AM
    Is it not a design flaw to have
    Any
    extend
    Unit
    ? This would be nice for overriding functions…
    p
    k
    +2
    • 5
    • 16
  • i

    Ifvwm

    07/19/2019, 6:29 AM
    I don't understand why java/kotlin have List and Array, 'cause C only have Array, Python only have List, Haskell have List, why java/kotlin have both? what's the meaning???
    🙄 1
    g
    • 2
    • 3
  • i

    Ifvwm

    07/19/2019, 6:31 AM
    a = [0..100] and b = {"a":1, "b":2} are so simple and plain to use
    k
    g
    • 3
    • 25
  • d

    David Cuesta

    07/19/2019, 6:40 AM
    Hi guys, Is there a way of parsing Kolin code? A library or something like that in order to obtain the function names, parameters, parameters types and outputs?
    i
    w
    +2
    • 5
    • 7
  • s

    Syed Faraz

    07/19/2019, 9:10 AM
    how do i use
    mapto
    plus
    takeif
    in chain, so that only those which satisfy operation are mapped to an arraylist?
    w
    t
    g
    • 4
    • 3
  • l

    LeoColman

    07/19/2019, 2:03 PM
    Guys, is it possible to create a function for both array and collection? They don't even have iterable in common 😞
    g
    s
    d
    • 4
    • 22
  • s

    Suraj Shah

    07/19/2019, 3:23 PM
    The line
    return@tryLambdas
    should throw an error here right? It does if i make it return
    String
    directly instead of generics. not sure what is going on here, could this be cause of type erasure?
    inline fun T tryLambdas(lamb : () -> T) : T{
        return lamb.invoke()
    }
    
    fun main() {
        tryLambdas<String>{
            return@tryLambdas // this should throw an error, but it doesnt. on decompiling it replaces it with Unit.INSTANCE
        }
    }
    k
    • 2
    • 28
  • s

    sonofblip

    07/19/2019, 7:14 PM
    Does anyone know a better way of doing this type of thing? using
    !!
    always makes me feel icky
    val x: Int? = getAnIntegerOrMaybeANullFromAPlaceO
    if (x != null) {
        functionThatTakesNonNullableIntegerArgument(x) // won't compile because it thinks x is nullable
        functionThatTakesNonNullableIntegerArgument(x!!) // will compile because added !!
    } else {
        // handle the null case
    }
    s
    p
    +2
    • 5
    • 7
  • m

    mathew murphy

    07/19/2019, 7:45 PM
    (Just in case a future Java version changes what ZonedDateTime will parse, or we switch to a different calendar or something...)
    d
    r
    l
    • 4
    • 26
  • r

    Ruckus

    07/19/2019, 8:01 PM
    Is there a way to tell the Kotlin compiler to treat certain Java methods with a
    void
    return as
    Nothing
    instead of
    Unit
    ?
    b
    • 2
    • 11
  • r

    Rafa

    07/19/2019, 9:31 PM
    Came across some Platform type issues related to annotations this week, and while I've used platform types before, never really thought deeply as to why they exist. Seems like everything that's returned from Java could just be treated as nullable. Looking at the docs:
    Any reference in Java may be null, which makes Kotlin's requirements of strict null-safety impractical for objects coming from Java. Types of Java declarations are treated specially in Kotlin and called platform types. Null-checks are relaxed for such types, so that safety guarantees for them are the same as in Java
    It seems as though it was a conscious decision to make the platform conform to Java. There are tradeoffs with all those choices, but curious as to why the reasoning was made to create the platform type instead of treating everything as nullable?
    d
    i
    • 3
    • 4
  • e

    egorand

    07/20/2019, 2:55 AM
    It’s just an iterable of iterables of
    T
    which gets flattened into a list of
    T
    . Here’s an example:
    [[1, 2, 3], [4], [5, 6]] -> flatten -> [1, 2, 3, 4, 5, 6]
    i
    s
    d
    • 4
    • 4
  • p

    Pere Casafont

    07/20/2019, 12:25 PM
    I just found something a bit puzzling in the language (thread)
    k
    e
    h
    • 4
    • 10
  • r

    Rodrigo Silva

    07/20/2019, 5:09 PM
    Hi all. How to access the R of kproperty1 <T, R>? For exemple: class Foo (val name: String) val test: String = Foo::name (getting error: "Required String, found KProperty1<Foo, String>)
    k
    k
    • 3
    • 3
  • a

    Andrew Gazelka

    07/20/2019, 9:06 PM
    Is class delegation (composition) considered a type of Mixin? Kinda confused on semantics.
    k
    s
    • 3
    • 2
  • h

    Hullaballoonatic

    07/21/2019, 12:02 AM
    my most desired features by likelihood they'll ever be added: * possible: default parameter types * unlikely: list literals.... * impossible: unbounded-range w/ operator
    b
    t
    • 3
    • 2
  • u

    Uzi Landsmann

    07/21/2019, 4:58 AM
    Perhaps someone (more qualified than me) should add a kotlin example to lazy initialization here: https://en.wikipedia.org/wiki/Lazy_initialization
    u
    k
    • 3
    • 2
  • t

    Tim Kuzmin

    07/21/2019, 1:49 PM
    Hey guys! I very like kotlin cause it’s very agile for the most situation f.e. I wanna have postfix version for ternary operator(i understand position of lang-developers about if-else). So, that’s my first solution:
    fun <T> Boolean.ternary(first: T, second: T) =
            if (this) first
            else second
    Any pro-programmer will tell u that in cases like this
    (stringA != null).ternary(stringA!!, stringB!!)
    we will have npe(parameters of function calculates before call). Lets make our function inline and add reified type:
    inline fun <reified T> Boolean.ternary(first: T, second: T) =
            if (this) first
            else second
    Nice! Now for non-primitives classes we will not have any trouble. I guess u’ve already understand what I mean. For primitives it doesnt work, cause even for inline function kotlin calculates primitive expressions and then call function. For me it’s looks like a bug. Does anybody know will it be fixed for next versions?
    d
    k
    • 3
    • 7
  • i

    Ifvwm

    07/21/2019, 3:08 PM
    fun counter():()->Int{
     var c=0
     fun g():Int{
      c++
      return c
     }
     return g
    }
    why “Function invocation g() expected”?
    m
    d
    k
    • 4
    • 13
  • r

    robstoll

    07/21/2019, 4:19 PM
    is it possible to do partial application with KFunction1 (to reduce it to KFunction0)
    c
    • 2
    • 7
  • h

    Hullaballoonatic

    07/21/2019, 4:49 PM
    I keep hearing about something soon to be added to Kotlin that allows us to modify the compiler. What is that?
    m
    u
    • 3
    • 5
  • h

    Hullaballoonatic

    07/21/2019, 4:53 PM
    Also, why is the language named "Kotlin"?
    m
    s
    l
    • 4
    • 15
Powered by Linen
Title
h

Hullaballoonatic

07/21/2019, 4:53 PM
Also, why is the language named "Kotlin"?
m

mbonnin

07/21/2019, 4:54 PM
https://en.wikipedia.org/wiki/Kotlin_(programming_language)#History
s

Shawn

07/21/2019, 5:00 PM
only tangentially related, but… the examples and copy on this page are decidedly not good lmao
>>
Kotlin provides Data Classes to define classes that store only properties. In Java programming, classes that store only properties are not unusual, but regular classes are used for this purpose. Kotlin has given provision to exclusively define classes that store properties alone. These data classes do not have any methods but only properties. A data class does not contain a body, unlike a regular class. data keyword is used before class keyword to define a data class.
m

mbonnin

07/21/2019, 5:07 PM
Yea and it doesn't organize information very well. The spread operator does look like it should be in position #4
l

louiscad

07/22/2019, 9:57 PM
Anyone can edit Wikipedia. You are not even required to create an account (but your IP address wil be used instead as long as it's not blacklisted). So, why not improve it?
m

mbonnin

07/22/2019, 9:58 PM
Because I'm trying to get a multiplatform project working first 🙂
@louiscad got a bit of time to kill waiting for a meeting so I made my first wikipedia edit: https://en.wikipedia.org/w/index.php?title=Kotlin_(programming_language)&amp;diff=907666841&amp;oldid=907398808. I hope I don't sound too much as a fan boy !
It's really the warm up, the section that needs the more love is certainly not the adoption one but I'm quite new to the process so let's see how this one goes first
l

louiscad

07/24/2019, 1:54 PM
That's a great start!
s

Shawn

07/24/2019, 2:35 PM
If you plan on working on the page a bit more, I’d strongly recommend giving this contribution page a read: https://en.wikipedia.org/wiki/Wikipedia:Writing_better_articles#Tone
or, at least that section anyhow
One of the biggest problems with many relatively nascent development-adjacent articles is a lack of consistent tone and presentation. This results in a very “tech blogger” feel which is rather inappropriate for Wikipedia and, imo, hurts the image of the subject
m

mbonnin

07/24/2019, 6:47 PM
Thanks. Are you saying that in relation to my change or as a more general advice ?
s

Shawn

07/24/2019, 6:49 PM
Just general advice, not trying to call you out specifically
m

mbonnin

07/24/2019, 7:35 PM
Ok thanks. Asking in case I could change something there. Don't hesitate if you see things could be rephrased (or well I guess you can edit directly too :))
View count: 2