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

    Jonathan Shore

    04/18/2019, 12:02 PM
    Any thoughts on extending inline classes to allow for multiple fields, where these would render as immutable objects in the JVM, but as proper pass by value and return by value stack frames in the native build? If / when the Java team eventually delivers value types in the JVM, the JVM target can be modified. I have many small objects that get created at high frequency in the work I do. For now I have to use object pooling to get reasonable performance, but for the most part these could be value types.
    d
    • 2
    • 2
  • s

    Smallville7123

    04/18/2019, 1:52 PM
    in
    val A = StringBuilder(string = "")
    val B = StringBuilder(content = "")
    what is the difference between
    string
    and
    content
    , like do both do the exact same thing?
    t
    s
    +2
    • 5
    • 33
  • s

    Smallville7123

    04/18/2019, 2:25 PM
    why do i get
    java.lang.ClassFormatError: Duplicate method name&signature in class file FileKt
    in https://pl.kotl.in/tLfGFlvku
    r
    • 2
    • 13
  • s

    Smallville7123

    04/18/2019, 3:49 PM
    why do i get
    Exception in thread "main" java.lang.IndexOutOfBoundsException: start 4, end 3, s.length() 3
    for https://pl.kotl.in/PEocYV7Ns
    fun String.padShrinkEnd(to: Int, char: Char): String {
        val thisLength = this.length
        val build = this.removeRange(to..thisLength).toStringBuilder()
        while(build.length < thisLength) build.append(char)
        return build.toString()
    }
    
    fun main() {
        println("\"" + "abc".padShrinkEnd(2, ' ') + "\"")
    }
    s
    i
    • 3
    • 8
  • s

    Smallville7123

    04/18/2019, 5:40 PM
    assuming this is correct, could this be optimized? https://pl.kotl.in/BKCVGjs_8
    j
    k
    • 3
    • 31
  • k

    karelpeeters

    04/18/2019, 6:27 PM
    Not directly, you can make a top-level function next to the class with the same name to fake a constructor though. (or an
    operator fun invoke
    on the companion but that's even uglier)
    j
    r
    s
    • 4
    • 3
  • k

    karelpeeters

    04/18/2019, 7:43 PM
    What's the error?
    t
    • 2
    • 12
  • s

    Smallville7123

    04/18/2019, 7:55 PM
    a
    for
    loop is faster than a
    forEach
    expression right?
    k
    l
    +3
    • 6
    • 43
  • s

    Smallville7123

    04/18/2019, 10:26 PM
    how can i force a
    when
    to continue to the next case even if the current case is valid for example
    val x = true
    val y = 1
    when(x) {
        true -> when(y) {
            1 -> // go to else of when(x) and not else of when(y), since false of when(x) will not match true
            else -> println("pass")
        }
        false -> println("statement")
        else -> println("fail")
    }
    a
    r
    r
    • 4
    • 6
  • s

    Smallville7123

    04/19/2019, 9:00 AM
    does multi-char unicode fit in a single Char
    c
    i
    k
    • 4
    • 8
  • a

    Antanas A.

    04/19/2019, 1:23 PM
    Hi, does Kotlin have some generic Tree<T> data structures and traversal functions on it?
    r
    • 2
    • 1
  • s

    Smallville7123

    04/19/2019, 3:59 PM
    are there any libraries that can convert a kotlin source directory into a... virtual heirachy tree complete with full source code information such that the source code is embedded with the information itself
    e
    s
    • 3
    • 3
  • s

    Smallville7123

    04/19/2019, 4:03 PM
    for example...
    src/main/kotlin/main.kt
    >
    val src = Heirachy.Source().directory[0].direcctory[0].directory[0].file[0].sourceCode
    
    val file = Heirachy.Source().directory[0].directory[0].directory[0].file[0].fileName
    println("source code for $file is\n$src\n")
    g
    • 2
    • 11
  • s

    Slackbot

    04/19/2019, 4:25 PM
    This message was deleted.
    s
    • 2
    • 1
  • s

    Smallville7123

    04/19/2019, 4:40 PM
    eg, such as bash, gcc, nm, ect
    s
    k
    r
    • 4
    • 18
  • s

    Sebastian Krajewski

    04/19/2019, 6:57 PM
    Hey, what's wrong here? I don't get any syntax error but compilator crashes with this message:
    Cause: Label wasn't found during iterating through instructions
    Element is unknownThe root cause was thrown at: LabelNormalizationMethodTransformer.kt:148
    -.kt
    s
    • 2
    • 13
  • p

    Pablo Schmid

    04/19/2019, 11:08 PM
    Hi All, Can somebody explain me how and why the map function is working with the element instead of the optional?
    -.kt
    c
    • 2
    • 16
  • l

    liminal

    04/20/2019, 2:35 AM
    Hi all, How can returnList be generated in a functional way?
    Untitled.kt
    g
    • 2
    • 3
  • m

    morcerfdumas

    04/20/2019, 7:54 AM
    But isn’t that the point of sealed classes? That they act like enums and help you perform pattern-matching, without the need of the
    else
    branch?
    p
    k
    g
    • 4
    • 28
  • s

    stevecstian

    04/21/2019, 8:10 AM
    Probably a wrong place to report this, but I'm getting 404 for https://pl.kotl.in right now…
    l
    s
    s
    • 4
    • 8
  • s

    Smallville7123

    04/21/2019, 1:24 PM
    how can i implement recursion without creating a variable via
    val
    or
    var
    and without creating a function via
    fun
    the closest i can get is a lambda expression
    { println("this is inside lambda") }
    but i am unable to assign a lable to it
    k
    n
    • 3
    • 14
  • s

    Slackbot

    04/21/2019, 3:30 PM
    This message was deleted.
    m
    m
    k
    • 4
    • 3
  • s

    Shawn A

    04/21/2019, 4:16 PM
    I am having trouble getting this code to work. Running into the issue shown in the pic.
    k
    • 2
    • 5
  • s

    stevecstian

    04/21/2019, 4:18 PM
    In case someone didn’t know, Kotlin Playground is a supported embed provider in embed.ly. As a result, we can embed Kotlin Playground code snippet on Medium directly.
    g
    k
    • 3
    • 4
  • s

    Slackbot

    04/21/2019, 7:54 PM
    This message was deleted.
    g
    • 2
    • 1
  • a

    aidan

    04/22/2019, 9:21 AM
    Good GUI plugin for intelliJ to view LOC?
    k
    • 2
    • 2
  • a

    ait

    04/22/2019, 11:01 AM
    I am wondering why this code is invalid (Conflicting overloads)
    -.kt
    c
    v
    +4
    • 7
    • 38
  • b

    bjonnh

    04/22/2019, 5:12 PM
    Not the best journalistic source but: https://www.businessinsider.com/why-google-square-atlassian-using-kotlin-programming-language-2019-4
    r
    m
    s
    • 4
    • 8
  • a

    Andrew Gazelka

    04/22/2019, 7:15 PM
    any reason why
    Sequence
    does not implement
    Iterable
    ? It is annoying to have to have two extension functions to support things which have a
    forEach
    method.
    s
    • 2
    • 2
  • d

    Daniel

    04/22/2019, 7:34 PM
    Might it be possible to create a spread operator for my own class? Lets say I have a class
    Operands : List<Operand>
    and I want to spread it with
    *operands
    instead of
    *operands.toTypedArray()
    which I have to use now
    r
    • 2
    • 3
Powered by Linen
Title
d

Daniel

04/22/2019, 7:34 PM
Might it be possible to create a spread operator for my own class? Lets say I have a class
Operands : List<Operand>
and I want to spread it with
*operands
instead of
*operands.toTypedArray()
which I have to use now
r

Ruckus

04/22/2019, 7:54 PM
No, the spread operator cannot be overloaded. The documentation has an exhaustive list of overloadable operators: https://kotlinlang.org/docs/reference/operator-overloading.html
If you want to propose it, you could try in #language-proposals, though I'm pretty sure it has been shot down before (though I can't recall exactly why)
d

Daniel

04/22/2019, 8:08 PM
Thank you for your answer! Totally fair when you know when its not overloadable. 🙂
View count: 1