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

    Hullaballoonatic

    04/13/2019, 10:42 PM
    And has there been any word on whether or not the following syntax will be added?
    val a = 1, b = 2, c = 5
    val d = "D", e = "e", f = "etc"
    Right now it's kind of possible as:
    val (a, b, c) = listOf(1, 2, 5)
    val (d, e, f) = listOf("D", "e", "etc")
    But I think the former is clearer
    🇳🇴 7
    s
    r
    • 3
    • 3
  • r

    Rohan Maity

    04/14/2019, 12:56 AM
    Kotlin is great language . But I still can't find any opportunities or jobs related to Kotlin . Most of them end up being Android dev. None for kotlin/server side . ☹️ Does anyone here know some opportunities and Jobs in Kotlin ?
    t
    l
    h
    • 4
    • 10
  • r

    robsonribeiro

    04/14/2019, 2:55 PM
    Hello everyone. I wonder if there is any certification for Kotlin just as it exists for Java?
    o
    • 2
    • 1
  • s

    Smallville7123

    04/14/2019, 3:33 PM
    is this normal? 2 gradle deamons:947MB:531MB, and 1 maven:106MB? along with IDEA:1.7GB
    t
    • 2
    • 1
  • s

    streetsofboston

    04/14/2019, 4:19 PM
    Does anyone else not like how JetBrains websites show the data-collection agreement view? Clicking the tiny Y or N or trying to type Y or N....it's cutesy, but not mobile friendly at all :( Also, sometimes you can't access it at all in embedded small Kotlin-playground samples...
    a
    • 2
    • 1
  • s

    Smallville7123

    04/14/2019, 4:31 PM
    what is the kotlin-native equivent to ::class.java.newInstance
    o
    g
    • 3
    • 3
  • j

    jdiaz

    04/14/2019, 5:07 PM
    What would be the reason behind only allowing public constructors on inline classes?
    k
    • 2
    • 5
  • s

    Smallville7123

    04/15/2019, 4:24 AM
    is this a correct implementation of
    .forEach
    inline fun forEach(action: (T?) -> Unit) {
            val iter = iterator()
            var it = iter.next()
            while(it != null) {
                action.invoke(p1 = it)
                it = iter.next()
            }
        }
    a
    • 2
    • 2
  • s

    Smallville7123

    04/15/2019, 4:24 AM
    as
    .forEach
    is part of
    java.Collections
    right?
    g
    • 2
    • 2
  • s

    Slackbot

    04/15/2019, 4:32 AM
    This message was deleted.
    t
    • 2
    • 2
  • s

    Smallville7123

    04/15/2019, 6:23 AM
    as im basically trying to implement
    java.util.ArrayDeque
    in kotlin native
    :thread-please: 2
    p
    • 2
    • 6
  • s

    Smallville7123

    04/15/2019, 7:03 AM
    is this correct?
    override fun iterator(): kotlin.collections.Iterator<T> {
            return object : kotlin.collections.Iterator<T> {
                var node = head
                override fun hasNext(): Boolean {
                    if (node != null) {
                        if (node?.next != null) return true
                    }
                    return false
                }
                override fun next(): T {
                    if (node != null) {
                        val value = node?.value
                        node = node?.next
                        return value as T
                    }
                    throw Exception("No Such Element")
                }
            }
        }
    :thread-please: 3
    a
    s
    • 3
    • 3
  • c

    CLOVIS

    04/15/2019, 10:00 AM
    How are extension functions handled when two of them are valid? As an example, I'm thinking of adding
    Any?.filter
    ,
    Any?.map
    etc extension functions, to help with null handling. How would the compiler react if it is used in a file in which
    List.filter
    (from the standard lib) is called? More precisely, if I write the following, which extension function would be called (assuming both are imported):
    val l = listOf (...)
    l.filter { it... }
    In that case they are both valid choices by the compiler, since
    List
    is also a
    Any?
    . So, which one is called?
    m
    • 2
    • 1
  • n

    nfrankel

    04/15/2019, 10:11 AM
    i’ve a (probably) stupid question: how to replace a line in a file? (i even never had this issue in java, so i don’t know how to do it in a simple way either)
    t
    • 2
    • 4
  • t

    thana

    04/15/2019, 10:52 AM
    are there any rules of thumb when to use extension functions and when to put them into the type itself?
    m
    d
    +2
    • 5
    • 7
  • a

    Ayoub

    04/15/2019, 12:55 PM
    Hello, does someone know how to create issues in the kotlin github repo ?
    t
    • 2
    • 2
  • s

    Smallville7123

    04/15/2019, 1:27 PM
    for iterator().hasNext() does the current element count as a true condition
    🇳🇴 3
    r
    g
    s
    • 4
    • 52
  • t

    thana

    04/15/2019, 1:37 PM
    by the way, is there way to ignore individuals on slack? asking for a friend...
    ➕ 2
    😂 15
    🇳🇴 2
    😢 2
    h
    • 2
    • 1
  • a

    Antanas A.

    04/15/2019, 2:06 PM
    Hi, Is it possible to have function which has two generic types and explicitly define only one type in call sites:
    `
            suspend fun <T, U> DataSource.mustHave(block: suspend T.() -> U): U =
                ((this as? T) ?: throw RuntimeException("Operation is not supported")).block()
    `
    and use it:
    dataSource.mustHave<DataSource.HasAddOperation> { add(command) }
    Logically it should be able to infer U type automatically, but if I'm specifying first type T compiler requires me to specify also U type. eg.
    dataSource.mustHave<DataSource.HasAddOperation, AddResult> { add(command) }
    Is it possible to somehow declare that extension function in a way that U type be inferred automatically?
    r
    c
    p
    • 4
    • 7
  • l

    LeoColman

    04/15/2019, 2:22 PM
    Isn't the slack moderated? Perhaps the moderation could take an action on spamming
    c
    • 2
    • 4
  • s

    Smallville7123

    04/15/2019, 2:49 PM
    does kotlin have its own version of
    Cloneable
    as i cant find it in the docs nor in the search thing at kotlinlang.org
    r
    f
    +2
    • 5
    • 25
  • p

    projectmoon

    04/15/2019, 3:01 PM
    currently i'm doing basically this:
    private var job: Job
    
    fun init() {
        GlobalScope.launch { job = launch { task() } }
    }
    
    fun stop() {
        GlobalScope.launch { job.cancelAndJoin() }
    }
    `
    p
    g
    • 3
    • 9
  • p

    projectmoon

    04/15/2019, 3:01 PM
    this feels extremely dirty to me. what is the more proper way to do this?
    a
    • 2
    • 2
  • s

    Smallville7123

    04/15/2019, 5:23 PM
    is there any way i can condense this further?
    if (returnDelimiters) false
    else it.equals(str)
    l
    s
    +2
    • 5
    • 5
  • o

    obobo

    04/15/2019, 6:14 PM
    I found a small mistake in the docs, where do I report this, github or youtrack?
    l
    • 2
    • 3
  • t

    tekjar

    04/15/2019, 6:15 PM
    Hi. I'm batching some data in a coroutine and sending the list over a channel. I'm assuming it'll be a data race if I clear this list after sending. Is there a method which return all the elements from the list and clears it?
    r
    g
    • 3
    • 2
  • s

    snowe

    04/15/2019, 7:39 PM
    tests should be able to access
    internal
    functions of
    open
    classes in the same package in main correct?
    k
    j
    m
    • 4
    • 71
  • g

    greg

    04/16/2019, 3:29 AM
    Hi, anyone knows a library with common data structures implementations? (directed graphs, btrees, etc.)
    d
    a
    • 3
    • 3
  • s

    Slackbot

    04/16/2019, 6:42 AM
    This message was deleted.
    g
    s
    • 3
    • 11
  • s

    Smallville7123

    04/16/2019, 7:44 AM
    is there any way to get a more... usable stacktrace other than
    Throwable().printStackTrace()
    as im trying to find what line in the function my function is throwing from
    t
    m
    • 3
    • 14
Powered by Linen
Title
s

Smallville7123

04/16/2019, 7:44 AM
is there any way to get a more... usable stacktrace other than
Throwable().printStackTrace()
as im trying to find what line in the function my function is throwing from
t

tddmonkey

04/16/2019, 7:45 AM
This information is in the stack trace
s

Smallville7123

04/16/2019, 7:45 AM
how would i aquire it?
t

tddmonkey

04/16/2019, 7:45 AM
What do you mean? What’s your context?
s

Smallville7123

04/16/2019, 7:52 AM
for example
fun abort(e: String = "Aborted"): Nothing {
    println("Aborting with error: $e")
    println("stack trace:")
    Throwable().printStackTrace()
    throw Exception(e)
}

fun main() {
    a()
}

fun a() {
    println("aborting from a:2 from SampleLinux.kt:20")
    abort()
}
output:
aborting from a:2 from SampleLinux.kt:20
Aborting with error: Aborted
stack trace:
kotlin.Throwable
        at kfun:sample.abort$default(kotlin.String;kotlin.Int)kotlin.Nothing (0x21a208)
        at Konan_start (0x21a182)
        at Konan_run_start (0x21a0f3)
        at Konan_main (0x21a047)
        at __libc_start_main (0x7f305064c223)
        at  (0x210029)
        at  ((nil))
Uncaught Kotlin exception: kotlin.Exception: Aborted
        at kfun:sample.abort(kotlin.String)kotlin.Nothing (0x21a490)
        at kfun:sample.abort$default(kotlin.String;kotlin.Int)kotlin.Nothing (0x21a208)
        at Konan_start (0x21a182)
        at Konan_run_start (0x21a0f3)
        at Konan_main (0x21a047)
        at __libc_start_main (0x7f305064c223)
        at  (0x210029)
        at  ((nil))
t

tddmonkey

04/16/2019, 7:54 AM
Is that kotlin native?
s

Smallville7123

04/16/2019, 7:54 AM
yes
t

tddmonkey

04/16/2019, 7:54 AM
you should probably ask that in the #kotlin-native channel then
❤️ 2
s

Smallville7123

04/16/2019, 7:55 AM
ok
m

Mike

04/16/2019, 12:22 PM
Comment on code if you’re worried about performance. You’re creating the stacktrace twice in your existing code because you create a Throwable, and an Exception.
val e = Exception(message)
e.printStackTrace()
throw e
or
throw Exception(message).also {
   it.printStackTrace()
}
s

Smallville7123

04/16/2019, 1:52 PM
ok? and im only interested in obtaining a backtrace
m

Mike

04/16/2019, 2:00 PM
Just an unasked for code review/comment. Creating a stacktrace can be expensive, and your original code was creating it twice. That’s all my point was. Don’t know of a cleaner approach to creating it, so nothing useful specific to your question.
t

tddmonkey

04/16/2019, 2:11 PM
Are you only interested in generating a stack trace, or do you want to throw it too? Your code indicates you also want to throw it. If you just want the stack trace you could do it directly:
`Thread.currentThread().stackTrace
s

Smallville7123

04/16/2019, 7:17 PM
is a backtrace and a stacktrace the same thing?
@tddmonkey Unresolved reference: Thread
View count: 7