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
getting-started
  • i

    Ian Lynagh

    11/09/2021, 3:53 PM
    Is there a tool that will take a set of
    *.kt
    files that form an application, and produce an equivalent single
    .kt
    file?
    v
    e
    • 3
    • 6
  • a

    Ansh Tyagi

    11/09/2021, 5:06 PM
    Hey! so is I am getting started with multiprocessing and wanted to know if there is something similar to pythons Pool.map() in kotlin?
    r
    g
    s
    • 4
    • 3
  • a

    Ayfri

    11/09/2021, 10:27 PM
    Hi, what are atomics and atomic operations ?
    👍 1
    j
    e
    • 3
    • 10
  • e

    eygraber

    11/10/2021, 5:25 AM
    I vaguely remember something about there being defined time periods between Kotlin releases (maybe it used to be here ). Is that accurate, or is there no guaranteed time between releases?
    v
    s
    • 3
    • 3
  • k

    Kenneth

    11/10/2021, 2:28 PM
    How do people do wsdl to kotlin?
    s
    s
    • 3
    • 3
  • n

    Nikolay Lebedev

    11/10/2021, 7:53 PM
    How can I create a class that takes a string and any other serializable class and has a method to return itself serialised into json encoded as string?
    d
    • 2
    • 1
  • r

    Richard Gomez

    11/10/2021, 8:49 PM
    Is there any documentation that clearly explains the difference between Kotlin's
    Regex
    vs. Java's
    Pattern
    ?
    v
    c
    +2
    • 5
    • 10
  • m

    Mo

    11/11/2021, 2:48 AM
    Hello, I'm to new to kotlin in general, and I love it. I'm intending to create an application for my personal use (finance), what is the recommended GUI library that I should use? I'm mainly going to use it on windows (so other platforms do not matter that much), and what kotlin platform should I use? (or learn?) or should I wait for the libraries/native/multiplatform support to get more stable before developing the application?
    j
    • 2
    • 1
  • e

    Erik Bender

    11/11/2021, 8:14 AM
    Hi 🙂 I have this function to deserialize generic lists from
    ByteArray
    fun mapBytesToList(arr: ByteArray): List<T> {
      if (arr.isEmpty()) {
        return emptyList()
      }
      val bais = ByteArrayInputStream(arr)
      var ois: ObjectInputStream? = null
      return try {
        ois = ObjectInputStream(bais)
        ois.readObject() as List<T>
      } catch (e: Exception) {
        emptyList()
      } finally {
        try {
          ois?.close()
        } catch (e: Throwable) {
        }
      }
    }
    I get a
    UNCHECKED_CAST
    warning at
    ois.readObject() as List<T>
    . Do you have a hint on how to improve this function?
    u
    • 2
    • 1
  • s

    Sivan

    11/11/2021, 9:25 AM
    Is it possible to add a kapt to the dev variant build only? Have to add a kapt for jdbc processor but we want to keep it only on our dev builds. Possible?
    e
    • 2
    • 1
  • m

    Marko Kunic

    11/11/2021, 9:51 AM
    is there a way to enforce ktlint checks in gradle build? eg. I run build or tests, and it fails because style isn't correct
    e
    • 2
    • 3
  • z

    Zode

    11/11/2021, 9:56 AM
    Is xcode13 compatible yet? I got an error when trying to build K/N
    FAILURE: Build failed with an exception.
    
    * Where:
    Build file '/Users/xxxx/Develop/kotlin/kotlin-native/build.gradle' line: 66
    
    * What went wrong:
    A problem occurred evaluating project ':kotlin-native'.
    > Incorrect Xcode version: 13.1. Required major Xcode version is 12.
    j
    • 2
    • 2
  • g

    Guru

    11/11/2021, 5:54 PM
    fun main() {
        val callback = { i: Int, j: Int ->
            val ii = i.times(j)
            val jj = j.times(ii)
            ii + jj
        }
    
        println(addAndMultiply(5, 6) { i, j ->
            i + 1 + j
        })
    
        println(addAndMultiply(5, 6, callback))
    }
    
    inline fun <T> addAndMultiply(x: T, y: T, call: (T, T) -> T): T where T : Number {
        if (x is BigDecimal || x is BigInteger) return call(x, y)
        if (y is BigDecimal || y is BigInteger) return call(x, y)
    
        return call(x, y) * x * y
    }
    I am getting reciever type mismatch at
    return call(x, y) * x * y
    Any Idea ?
    l
    • 2
    • 1
  • m

    martmists

    11/11/2021, 7:24 PM
    Where should I go if I get this error?
    org.jetbrains.kotlin.backend.common.BackendException: Backend Internal error: Exception during IR lowering
    Platform is JVM, and it seems like it has to do with my suspend functions
    m
    • 2
    • 1
  • m

    martmists

    11/12/2021, 1:58 AM
    Implementation detail: If I write an extension function like so:
    val Extension.dispatcher by lazy {
        SomeDispatcher()
    }
    Will the
    dispatcher
    property be different for every Extension or will there be one global dispatcher
    r
    • 2
    • 1
  • s

    Simon Lin

    11/12/2021, 7:58 AM
    How to flatten a list that deep layer is not same: ex1:
    val deepList = listOf(
        listOf(
            listOf(-1, 0),
            listOf(1)
        ),
        listOf(2, 3),
        listOf(4, 5, 6)
    )
    println(deepList.flatten()) // [-1, 0, 1, 2, 3, 4, 5, 6]
    ex2:
    val deepList = listOf(
        -1,
        listOf(listOf(listOf(0))),
        listOf(2, 3),
        listOf(4, 5, 6)
    )
    println(deepList.flatten()) // [-1, 0, 1, 2, 3, 4, 5, 6]
    t
    u
    • 3
    • 7
  • p

    Pavel Repkin

    11/12/2021, 11:21 AM
    Hi! I don’t see a multiplatform channel. Where should I ask questions on multiplatform development?
    j
    • 2
    • 2
  • m

    Moritz Post

    11/12/2021, 11:30 AM
    hello i have a list of numbers in the range 1-255. how could i transform these numbers into a
    ByteArray
    ? a direct conversion via
    byteArrayOf
    does not work since the numbers are unsigned but
    ubyteArrayOf
    does also not work for a reason i don't fully understand. It would be possible to map each number to
    it - 128
    but that seams a bit unefficient. Help would be appreciated.
    k
    p
    • 3
    • 4
  • t

    Tomas Kormanak

    11/12/2021, 12:13 PM
    Is there some function like
    with
    which is ignoring return value and returns
    Unit
    ? Something like this:
    public inline fun <T> with(receiver: T, block: T.() -> Unit): Unit {
        receiver.block()
    }
    Or any better idea how to avoid explicitly returning Unit in this case:
    fun process(data: Data) = with(data) {
        ///doSomething
        Unit
    }
    r
    v
    +2
    • 5
    • 6
  • m

    Matias Reparaz

    11/12/2021, 1:18 PM
    Hi, I have an interface with a method like this
    fun doSomething(param: SomeParams): Single<Something>
    where Single is from RxJava. I want to use coroutines inside my implementation and wrap the value at the end. But how can I create the CoroutineContext? It’s ok to use the runBlocking in this context? something like this:
    fun doSomething(param: SomeParams): Single<Something> = Single.just(
       runBlocking {
            doSomething()
        }
    )
    suspend fun doSomething(): Something = TODO()
    Thanks
    m
    • 2
    • 2
  • m

    mcpiroman

    11/13/2021, 11:58 AM
    Is there a shorter way to write:
    val rng = Random(0)
    generateSequence { rng.nextInt() }.take(10).toList()
    j
    • 2
    • 1
  • d

    Danny Morgan

    11/13/2021, 12:41 PM
    https://play.kotlinlang.org isn't working for me since yesterday afternoon (12 Nov)... Anyone have information about this? (specifically, even with hello world example at start; it returns errors) (update) an issue has been filed https://youtrack.jetbrains.com/issue/KT-49687
    ✅ 1
    j
    • 2
    • 3
  • d

    dave08

    11/14/2021, 10:57 AM
    Given:
    class Foo(val bar: Bar)
    class Bar(val baz: String)
    
    
    val foo = Foo(Bar("baz"))
    
    // why isn't this possible?
    val bazGetter = Foo::bar::baz
    
    // whereas this is ok?
    val bazGetter2: (Foo) -> String = { it.bar.baz }
    j
    s
    e
    • 4
    • 5
  • r

    reactormonk

    11/15/2021, 11:52 AM
    Is there a way to figure out where something's being constructed in a project with a whole lot of javax
    @Inject
    flying around? Or what's the usual way to extract parts of the codebase and sending a few arbitrary values through it for exploration purposes? I feel like I'm trying to fight the structure of the codebase here if I'm trying to construct everything manually.
    m
    • 2
    • 2
  • m

    Mendess

    11/15/2021, 12:10 PM
    How do I know if a lateinit local variable is initialized?
    fun foo() {
        lateinit var x: Int
        if (::x.isInitialized()) {}
    }
    This doesn't seem to work
    j
    h
    s
    • 4
    • 14
  • a

    Ayfri

    11/15/2021, 2:45 PM
    Hi, I have two numbers that are random, can be negative, first can be above second or not or even equal. I want to create a range between these two numbers that always have a step of
    1
    and start always at the lower number, how can I do it in a simple way ?
    j
    • 2
    • 3
  • b

    Bernhard

    11/15/2021, 2:52 PM
    Hi, I've got a data class but in one case I want one attribute of it to be evaluated again on each access (getting the current date basically). How do I do this?
    m
    p
    • 3
    • 12
  • s

    Steve Kim

    11/15/2021, 4:58 PM
    Hi, We have officially released 5 kmm libraries. https://twitter.com/LINE_DEV_EN/status/1456180731965706248?s=20
    j
    • 2
    • 2
  • e

    eygraber

    11/16/2021, 4:00 AM
    Is there a "kotlin" way to do something like
    Scanner(myFile).findAll(myPattern)
    that returns a `Sequence<String>`(I know I can call
    asSequence
    on the returned
    Stream
    but I'm wondering if there's a specific Kotlin API for that)?
    p
    r
    +2
    • 5
    • 8
  • a

    ankushg

    11/16/2021, 7:52 AM
    Doing a cleanup of a codebase and marking some stuff as
    @Deprecated
    A couple pain points that are popping up: 1. Deprecated code tends to call other deprecated code, and this generates too many warnings. I currently have a ton of
    @Suppress("KotlinDeprecation", "DEPRECATION") @Deprecated
    declarations all over my codebase, when there are only one or two actual places that are using the top-level, public Deprecated method. 2. Deprecations in
    import
    statements are tricky.
    When I intentionally use a deprecated declaration, I can
    @Suppress
    it at the call site. But I can't
    @Suppress
    the warning I get just for importing it! For top-level declarations, I can use the fully-qualified name everywhere and just avoid importing the deprecated declaration. This doesn't work when you're using an extension function contained in an
    object
    though. Questions: • Is there a way to automatically suppress Deprecation warnings within declarations that are also Deprecated? • Is there a way to get the compiler to ignore when a
    @Deprecated
    declaration is imported, but still warn when it is used? • Or alternatively: is there a way I can use a fully-qualified name to avoid importing an extension function contained in an
    object
    ?
    r
    • 2
    • 2
Powered by Linen
Title
a

ankushg

11/16/2021, 7:52 AM
Doing a cleanup of a codebase and marking some stuff as
@Deprecated
A couple pain points that are popping up: 1. Deprecated code tends to call other deprecated code, and this generates too many warnings. I currently have a ton of
@Suppress("KotlinDeprecation", "DEPRECATION") @Deprecated
declarations all over my codebase, when there are only one or two actual places that are using the top-level, public Deprecated method. 2. Deprecations in
import
statements are tricky.
When I intentionally use a deprecated declaration, I can
@Suppress
it at the call site. But I can't
@Suppress
the warning I get just for importing it! For top-level declarations, I can use the fully-qualified name everywhere and just avoid importing the deprecated declaration. This doesn't work when you're using an extension function contained in an
object
though. Questions: • Is there a way to automatically suppress Deprecation warnings within declarations that are also Deprecated? • Is there a way to get the compiler to ignore when a
@Deprecated
declaration is imported, but still warn when it is used? • Or alternatively: is there a way I can use a fully-qualified name to avoid importing an extension function contained in an
object
?
r

Ruckus

11/16/2021, 3:28 PM
You could just suppress deprecation warnings for the entire file (assuming the code is organized in such a way that deprecated stuff is clumped together in files without non-deprecated stuff).
a

ankushg

11/16/2021, 3:38 PM
Yeah that's my current fallback but there are definitely files that have only one deprecated method that imports other deprecated stuff and many perfectly fine methods that I don't want to suppress deprecations for 😔
View count: 1