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
announcements
  • c

    Chills

    03/19/2020, 5:26 PM
    i have a template
    aligned With Code"""
    ................ class Dance{
    ...................companion SType{
    .........................dress = "BW"
    .......................}
    .................}
                     """
    how to trim this (the dots are spaces which need to trimmed) ,so after format those spaces gets trimmed
    c
    s
    • 3
    • 10
  • c

    Colton Idle

    03/19/2020, 6:22 PM
    I'm having a perf issue in IntelliJ/AS with larger projects with kotlin. If I have
    val asdf = "asdf"
            when (asdf) {
                "abc" -> {
                }
                else -> {
                }
            }
    and then comment out the first line, it takes about 15 seconds for the
    when
    statement to show as invalid (the asdf var is underlined in red). How would I get a trace in order to file a bug for this? How can I help JB with this issue?
    a
    t
    • 3
    • 8
  • m

    Michael Limb

    03/19/2020, 7:47 PM
    why am i getting this when the var is internal?
    s
    z
    • 3
    • 8
  • c

    Chills

    03/19/2020, 8:07 PM
    logger how to use in function as there are no class and how to make it common so logger.info or similar can do and also want to loglevel set at global. not sure how to do it kotlin.
    z
    j
    • 3
    • 8
  • n

    New111

    03/19/2020, 9:11 PM
    Hi all, our kotlin app reads a lot of data from database but does this in very inefficient way (no caching at all). Is there any library for kotlin which could be used as intelligent/smart cache between kotlin and DB ? By intelligent/smart I mean I could specify how much memory it can use at max and it will never go over this limit but if there are more data than cache can store it will purge some of them to not break the limit ? I'd like to avoid OOM-ing my app (and it will work in docker as well ...)
    c
    e
    • 3
    • 12
  • j

    jaguililla

    03/20/2020, 8:47 AM
    That’s the way logging libraries get that information
    c
    • 2
    • 2
  • d

    Dico

    03/20/2020, 11:40 AM
    with(vk) { this@create.enumerate() }
    e
    • 2
    • 9
  • o

    Oscar Sequeiros

    03/20/2020, 2:23 PM
    I'm writing a IntRange with the end excluded. I was thinking if there is a way to declare a class (range in my specific case) as:
    val range = IntRange[2, 5)
    That express as maths, interval with closed at 2, opened at 5.
    s
    s
    • 3
    • 5
  • p

    PandaH.

    03/20/2020, 2:27 PM
    Hello, I'm coming to kotlin from typescript and was wondering how to translate this typescript code to kotlin:
    // typescript
    type ID = String;
    function generateId(obj): ID { ...body... }
    basically, how to create types like above. i came up with this, but im not sure if its the best way:
    // kotlin
    class ID : String()
    fun generateId(obj: Obj): ID { ...body... }
    thank you!
    d
    j
    b
    • 4
    • 4
  • p

    PandaH.

    03/20/2020, 2:28 PM
    also, what about types like this:
    type Fruits = "Apples" | "Oranges" | "Bananas";
    , what would be the kotlin equivalent?
    d
    i
    • 3
    • 2
  • n

    nickheitz

    03/20/2020, 2:59 PM
    Does anyone here know how, or if it is possible, to use the new type inference when compiling scripts with the embedded compiler?
    m
    • 2
    • 5
  • o

    Orhan Tozan

    03/20/2020, 3:37 PM
    Shouldn't a
    @Deprecated
    class have all of its method automatically marked as deprecated?
    🇳🇴 4
    d
    s
    • 3
    • 23
  • b

    basher

    03/20/2020, 4:36 PM
    Feel like this should have had more press in the 1.3.70 blog post or release notes, but you can now add
    -Xexplicit-api={strict|warning}
    to make the compiler force you to add visibility modifiers. maybe still experimental? but awesome to see this coming for library authors
    i
    • 2
    • 3
  • s

    Steve

    03/20/2020, 10:11 PM
    I have a validation routine that has a few different steps (thing must be X long, prefix before the '-' must be Y long, prefix must conform to this mask, etc). Is there a more Kotlin-y way to do this besides a bunch of
    if(!validateLength(thingy)) if(!validatePrefixLength())
    statements?
    s
    • 2
    • 4
  • p

    Paul Woitaschek

    03/20/2020, 11:00 PM
    Is it a complier bug that this fails with an overload resultion ambiguity? https://github.com/PaulWoitaschek/FlowPref/blob/abeb54d82a58cd09fae5392624ad725e26804e28/android/src/test/java/de/paulwoitaschek/flowpref/android/FlowPrefTest.kt#L150
    • 1
    • 1
  • c

    Chills

    03/21/2020, 7:33 AM
    how to start koin , when it requires fun? https://pastebin.com/PUHaf1Tu startkoin can't start without function 😞
    m
    • 2
    • 5
  • l

    LastExceed

    03/21/2020, 3:21 PM
    suspend fun main() {
    	val x = getItems1()
    	val y = getItems2()
    }
    
    suspend fun getItems1() = httpClient.get<PayloadContainer<Items>>("<https://api.warframe.market/v1/items>").payload
    
    suspend fun getItems2() = httpClient.getUnwrapped<Items>("<https://api.warframe.market/v1/items>")
    
    suspend inline fun <reified PayloadType> HttpClient.getUnwrapped(url: String) =
    	get<PayloadContainer<PayloadType>>(url).payload
    
    //for some reason this API wraps all it's payloads in another payload so we need to unwrap 1 layer
    
    data class PayloadContainer<PayloadType>(val payload: PayloadType)
    getItems1()
    works perfectly fine,
    getItems2()
    gives me the following error:
    class java.util.LinkedHashMap cannot be cast to class payload.Items (java.util.LinkedHashMap is in module java.base of loader 'bootstrap'; payload.Items is in unnamed module of loader 'app')
    can someone explain the problem? It seems to have to do with type erasure, but shouldn't
    reified
    prevent that ?
    j
    • 2
    • 1
  • l

    LastExceed

    03/21/2020, 8:21 PM
    is there a way to get something like "inner objects" ? an object inside a class that has access to the outer classes properties? or maybe im completely oblivious of something obvious?
    b
    • 2
    • 7
  • j

    Janelle Fullen

    03/22/2020, 1:36 AM
    Can someone help me with getting my composite build setup to run? Thanks!
    i
    • 2
    • 1
  • j

    Janelle Fullen

    03/22/2020, 1:48 AM
    Also this is Gradle 6.1.1
    e
    • 2
    • 8
  • v

    v79

    03/22/2020, 9:49 AM
    I have a collections groupBy / filter / map / reduce challenge I can't quite get right. Can anyone help? I think I might be trying to do to much in a single line of code: given:
    allTags [
    			tag { category: "genre", value: "classical", count=0, multiple=false },
    			tag { category: "genre", value: "jazz",, count=0, multiple=false },
    			tag { category: "composer", value: "mahler", count=0, multiple=false },
    			tag { category: "composer", value: "bach", count=0, multiple=false },
    			tag { category: "genre", value: "classical", count=0, multiple=false },
    			tag { category: "composer", value: "bach", count=0, multiple=false },
    	]
    I want:
    groupedList [
    			tag { category: "genre", value: "classical", count=2, multiple=true },
    			tag { category: "genre", value: "jazz", count=1, multiple=false },
    			tag { category: "composer", value: "mahler", count=1, multiple=false }
    			tag { category: "composer", value: "bach", count=2, multiple=true }
    	]
    // TODO: this isn't counting correctly
    val groupedList = allTags.groupBy { it.label }.values.map { it.reduce { acc, item -> Tag(category = item.category, label = item.label, url =  item.url, postCount = item.postCount++, hasPosts = item.postCount > 1) } }
    s
    • 2
    • 3
  • c

    Chills

    03/22/2020, 11:17 AM
    IIFE in kotlin?
    t
    • 2
    • 1
  • e

    Edoardo Luppi

    03/22/2020, 11:27 AM
    @Janelle Fullen I was running Gradle 6.3 RC on JDK 14, switched to JDK 8, everything works... Like, big wtf
    j
    • 2
    • 12
  • l

    LastExceed

    03/22/2020, 2:58 PM
    why can't an interface inherit from a class ? the use case would be using properties of that class in the interface's default function implementations
    s
    p
    • 3
    • 7
  • a

    Animesh Sahu

    03/23/2020, 9:13 AM
    How do i invite somebody to this kotlinlang.slack.com ?
    a
    l
    • 3
    • 2
  • l

    LastExceed

    03/23/2020, 12:11 PM
    how can i iterate through all properties of a data class instance with reflection so i can get both the name and the value of the property? I tried
    fun main() {
    	val thing = MyClass(42, "69")
    
    	thing::class.memberProperties.forEach {
    		println(it.name)
    		println(it.get())
    	}
    }
    
    data class MyClass(val x: Int, val y: String)
    but
    get()
    requires a parameter of type
    Nothing
    which i dont understand
    e
    d
    a
    • 4
    • 5
  • a

    aipok

    03/23/2020, 12:18 PM
    Where can I see 1.3.71 changelog?
    d
    r
    t
    • 4
    • 6
  • u

    user

    03/23/2020, 1:03 PM
    message has been deleted
    🎉 16
    🔥 9
    m
    j
    • 2
    • 2
  • r

    Ruckus

    03/23/2020, 2:15 PM
    Are the new `fun interface`s inline when used in an online fun?
    l
    • 2
    • 1
  • p

    Pacane

    03/23/2020, 2:27 PM
    Is there a way to use the
    use
    keyword and also catch exceptions? Seems like the exception doesn't reach the caller of
    doSomething
    override fun doSomething() {
            sessionCreator.createSession().use(fun(session: SqlSession) {
                // Some code
                throw Exception("Test Exception")
            })
        }
    s
    r
    • 3
    • 4
Powered by Linen
Title
p

Pacane

03/23/2020, 2:27 PM
Is there a way to use the
use
keyword and also catch exceptions? Seems like the exception doesn't reach the caller of
doSomething
override fun doSomething() {
        sessionCreator.createSession().use(fun(session: SqlSession) {
            // Some code
            throw Exception("Test Exception")
        })
    }
s

spand

03/23/2020, 2:39 PM
Doesnt seem right.
use()
rethrows the exception
p

Pacane

03/23/2020, 2:39 PM
I think you're right
It's getting lost somewhere else
r

Ruckus

03/23/2020, 3:32 PM
Also, a bit pedantic, but
use
is just a function, not a keyword.
👍 1
View count: 4