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
forum
  • r

    rss

    02/16/2023, 3:49 PM
    Serialize a function to JSON Is there a way to serialize a function to JSON? I try to do Json.encodeToString(fun(i:Int): Int = i * 2) I get “Class () is not registered for polymorphic serialization in the scope of ‘Function1’. Mark the base class as ‘sealed’ or register the serializer explicitly”. Marking the class as sealed does not work in my case as I don’t want to make this class abstract. In any case, this should have nothing to do with where the code is run from. 1 post - 1 participant <a...
  • r

    rss

    02/16/2023, 4:09 PM
    [Feature request] Add encrypt() and decrypt() extension functions to String Decrypting and encrypting is very complicated, but why does it need to be this way? Would it be possible to simply have an encrypt function that takes in an encryption key (that should be minimum at the size of a UUID, 128 bit), and then a decrypt function where you send in the same key to decrypt? Example: val encryptedString = "My string".encrypt(encryptionKey) println(encryptedString.decrypt(encryptionKey) The same crypto algo will be used everywhere, but is that a problem as long as the...
  • r

    rss

    02/17/2023, 7:59 PM
    Missing setter implementation not detected by compiler The following compiles successfully but throws an AbstractMethodError at runtime (1.8.10). interface Interface { var a: String } open class Open { val a: String = "default" } class Impl : Open(), Interface fun main() { val x = Impl() println(x.a) x.a = "" } Why does the compiler allow this? Is this a known problem or am I missing something? 1 post - 1 participant <a...
  • r

    rss

    02/19/2023, 9:19 PM
    Kotlin +KorGE Hi i started to learn Kotlin and was lokking for making turn based game.I found KorGE library but i dont know how to make turn based games in Kotlin or if KorGE will be good library for this? So can somebody can help me i dont know maby some courses how to make turn based games or some advices? 1 post - 1 participant Read full topic
  • r

    rss

    02/21/2023, 6:59 PM
    Hours to upgrade Kotlin Hi, I’m new to mobile development, but have taken on responsibility for an existing app developed in 2019. I’m looking for a new dev team. One group told me that before they could work on it, I need to upgrade Kotlin, which they say requires about 35 billable hours. I need a reality check. 35 hours seems like a lot of time. I have no idea whether it’s (a) necessary or (b) if it really requires 35 hours. Does this sound reasonable? 1 post - 1 participant <a...
  • r

    rss

    02/22/2023, 2:59 AM
    How do I call InputEvent.inputType in Kotlin/js I checked the standard library. Without this attribute in the InputEvent - Kotlin Programming Language, but in the standard WebAPI has this property InputEvent.inputType - Web API 接口参考 | MDN So how do I call this...
  • r

    rss

    02/23/2023, 1:59 AM
    Why is awaitAll error handling so counter-intuitive? I’m noticing some counter-intuitive error-handling behavior when using awaitAll. For example: suspend fun main(): Unit = coroutineScope { val deferred = async { throw Exception("fake") } try { listOf(deferred).awaitAll() } catch (e: CancellationException) { println("CancellationException: $e") } catch (e: Throwable) { println("Throwable: $e") } } This is caught in the first catch, but if I replace listOf(deferred).awaitAll() with just deferred.await(), then the...
  • r

    rss

    02/24/2023, 11:49 AM
    New test run in Kotlin/JS Has anyone successfully created a project where they have a separate JS compilation and test run using it? I’m using the IR compiler in a multiplatform project, if that makes any difference. At first it seems like the way you’re supposed to do this is use the testRuns container, with something like: kotlin { js(IR) { browser {...
  • r

    rss

    02/27/2023, 11:29 AM
    Extension function with type Any I was trying to write a more generic extension function which counts elements of all lists in a map: So, instead of val Map.listElementCount: Int get() { var total = 0 for (list in this.values) { total += list.size} return total } I would like to write as I then could apply it to all Maps with a List of values val Map.listElementCount: Int get() { var total = 0 for (list in this.values) { total += list.size} return total } This...
  • r

    rss

    02/27/2023, 7:29 PM
    Avoid using `runBlocking` in tests Is there a way to avoid using runBlocking in tests? I currently have the following: class ServerTest { @Test fun testLocalServer() = runBlocking { ... } @Test fun testStagedServer() = runBlocking { ... } } I would like this to somehow become: @Test fun testLocalServer() { ... } @Test fun testStagedServer() { ... } Basically, I want my code to look like the second code block but still behave exactly like the first code block. I am assuming that I will want every...
  • r

    rss

    02/28/2023, 2:29 AM
    Coroutines for low latency/zero gc software I’ts been few years since i last used coroutines, nowdays i’m doing low latency and zero gc software, essentially systems where once application is bootstraped and jvm warmed up no objects are to be created especially on critical path. We often use our own event loop implementations (we = Chronicle Software) which are often busy spinning on a cpu. For some applications where interaction with an external services amounts to an event being published and another event eventually observed to read...
  • r

    rss

    02/28/2023, 11:29 AM
    How to create a progress bar that shows the real completion percentage of a task I would like to add a progress bar showing the real percentage of completion of a task (compressing a video using ffmpeg) in my app. At the moment, I just found examples with delays that seem real, but they aren’t. Right now, I’m using Progress Dialog: progressDialog = ProgressDialog(requireActivity()) progressDialog.setTitle("Please wait..") progressDialog.setCancelable(false) progressDialog.setCanceledOnTouchOutside(false) but I don’t know how to show the percentage and...
  • r

    rss

    03/01/2023, 11:49 AM
    Courutines cancellation exceptions Hey For Kotlin Multiplatform projects: Is it possible to implement coroutines or threads for Kotlin/Native or Kotlin Coroutines that throw a cancellation exception? Quote from this blog post where the problem of “Shrödinger’s Coroutines” is defined: Cancellation exceptions shouldn’t be ignored or suppressed, because that could cause a cancelled coroutine to...
  • r

    rss

    03/01/2023, 5:49 PM
    What are my options for auto code generation from text file? I have a text file like this: name: "Foo" metric { type: COUNTER } field { name: "bar" type: BOOL } And I want Kotlin to parse the file, extract field values, and generate function, like below, and append that function to the existing file FooBar.kt fun countFoo(bar: Boolean) { println("Success: $bar") } I found code generation from annotations but are there any well supported packages in Kotlin that will allow me to do what I described or should I go back to C++ thanks...
  • r

    rss

    03/02/2023, 5:29 AM
    Coroutine select - need onJoin or onAwait that cancels if not chosen If I’m not mistaken, calling onJoin on a Job inside select will NOT result in the job being canceled if another clause is chosen (same with onAwait.) However, this is absolutely functionality I will regularly use in the context of a game engine – for example, implementing a select clause like onEvent by launching a job that will invoke a suspending function under the hood (i.e. the non-select implementation) then invoking onAwait on it, ideally. However the job should be completely...
  • r

    rss

    03/03/2023, 4:09 AM
    Differences between Resources and Locations plugin in ktor? The docs for them look almost identical. What is the difference? 1 post - 1 participant Read full topic
  • r

    rss

    03/03/2023, 6:29 PM
    Composition visibility I suppose, internal visibility is rarely used in projects because it’s wide and packages are shuffled often. But what could be useful is a visibility scope to be seen only between children and parents or composition variables. Like class Foo() { internal_private fun invisibleOutside() {} } class Bar(foo: Foo) { init { foo.invisibleOutside() } } And it’s good to be available in interfaces as well. 1 post - 1 participant <a...
  • r

    rss

    03/03/2023, 10:49 PM
    How to default null values on a data class? I have the following class with a default value for the property name. data class Location constructor( val lat: Double, val lon: Double, val name: String = "" ) Fine. If I call the constructor without passing a value for name, it initializes properly with the empty string but… Not fine, it gets called with the argument null by a deserialization framework (and maybe other frameworks). If I make the constructor parameter nullable and not a val, I can’t make it a data class so I...
  • r

    rss

    03/04/2023, 11:19 PM
    Operator function for getting boolean value of object Has this ever been officially suggested? To allow something like Python’s __bool__? class BooleanThing{ operator fun bool() = true } fun main() { if (BooleanThing()) { println("Hello World") } } 1 post - 1 participant Read full topic
  • r

    rss

    03/06/2023, 3:59 AM
    Trouble when interpreting Kotlin specifications Hello all, I’m having trouble figuring out how the Kotlin specification’ Syntax and grammar should be interpreted. For instance, when reading the section on while-loops, quote: 'while' {NL} '(' expression ')' {NL} (controlStructureBody | ';') Here we could see that while is followed by <a href="https://kotlinlang.org/spec/syntax-and-grammar.html#syntax-and-grammar" rel="noopener...
  • r

    rss

    03/06/2023, 7:59 AM
    My experience with "select" in coroutines Hi folks, I wanted to talk a little about my experience with coroutine select in the context of a game engine. First of all, I’m very happy that it exists in Kotlin! Coroutines are so incredibly useful, and there’s so much yet-unexplored potential for game design purposes, so thank you JetBrains! The select part of the library seems experimental and little spoken of, so I wanted to talk about it a bit, and maybe where my needs are differing from what’s provided. Here’s an example script taken...
  • r

    rss

    03/06/2023, 10:39 AM
    Setting fillStyle on Canvas using new WASM issue I am trying to set fillStyle on a HTML Canvas using the new KotlinWASM. If I pass a string - I get a compiler error. If I force it to Dynamic (to pass typing), I get the browser crashing say the passed value is opaque. * Compile Error (when String is passed)* file😕//Development/wasmMandlebrot/src/wasmMain/kotlin/canvas.kt:9:42 Type mismatch: inferred type is String but Dynamic? was expected Browser Error (when Dynamic is passed) Uncaught (in promise) TypeError: WebAssembly objects are...
  • r

    rss

    03/06/2023, 1:59 PM
    Typealias with generic Let’s say I have a class container like this: class Container Then I have a handler like this: interface Handler{ fun map(c:Container):Pair fun add(c1:Container, c2:Container):Pair } Later I want to add another generic to container and handler, let’s call it F. Or i want to remove B and C from container and handler. Currently I have to make change at multiple places of the code, but I would like to have an opportunity to change the code not so often. Like to create a typealias in handler:...
  • r

    rss

    03/06/2023, 7:59 PM
    `@PublishedAPI private fun` Why does @PublishedAPI only work for internal functions? I have a file-private function I want use from an inline function. I need to make it internal in order to work with @PublishedAPI. But I don’t want to expose this function to the rest of the module. I understand this has to do with java interoperability. This is a complex topic for me since I write 100% kotlin now, and never have to deal with java. In <a...
  • r

    rss

    03/07/2023, 10:59 AM
    Kotlin idiomatic implementation of I have written the following function to find a histogram median. The loop with an external running total looks ugly compared to other more kotlin-esque code. Is there a way to make it more ‘elegant’ without compromising performance? I suspect that there is a function on collections that might do this, but I am not sure which. I would like to be told of it and how to use it… that is the way I learn. /** * Assuming that the receiver is a histogram where the value at each index is the count...
  • r

    rss

    03/07/2023, 8:59 PM
    Eliminate redundancy of context receiver when overriding a function Hi all, What do you think of eliminating the redundancy of context(Scope) when overriding a function that already have it? In this snippet, wouldn’t it make more sense if we were able to just override performAction without explicitly adding context(Scope)? 1 post - 1 participant Read full topic
  • r

    rss

    03/07/2023, 9:19 PM
    "DataType" for only initial null value For various reasons I work with classes which contain variables for objects which only can be null if not initialized. I would like this as an option to declare. class Hull { var nodeHullOptions: List? = null private set } I would suggest a third option: Do not allow to assign null again, maybe mark it with an additional exclamation mark: class Hull { var nodeHullOptions: List?! = null private set } The compiler can then do all the same checks it would do...
  • r

    rss

    03/08/2023, 5:39 PM
    Do I need to know JAVA to get started in KOTLIN? On the website android.com it says that the minimum requirement to study and start programming in kotlin is to know JAVA, C ++ related language for at least 2 years. Why do you only have a notion of programming, what does the person do, learn JAVA and then KOTLIN or learn KOTLIN directly? Android Developers <a...
  • r

    rss

    03/08/2023, 6:19 PM
    External Interface Required Fields When using Kotlin JS with libraries such as react, you may frequently create external interfaces for react props you want to use. They have to be external interfaces because they extend the external interface Props and Kotlin doesn’t like to extend external stuff with internal classes/interfaces.The problem is that if you want to specify required fields you have to essentially create a function wrapper to enforce which fields are required. In Typescript, using their equivalent to external...
  • r

    rss

    03/09/2023, 1:19 AM
    java.lang.NoSuchFieldError : INSTANCE I’m starting here instead of a youtrack issue because I cannot recreate the issue in an MRE and I cannot post the project because it is company code. I’m hoping someone can lead me to reproduce it as an MRE here. I have a normal jvm project with a unit test. This unit test ends up using this object declaration. During runtime, it throws the exception java.lang.NoSuchFieldError : INSTANCE here: <a class="lightbox"...
Powered by Linen
Title
r

rss

03/09/2023, 1:19 AM
java.lang.NoSuchFieldError : INSTANCE I’m starting here instead of a youtrack issue because I cannot recreate the issue in an MRE and I cannot post the project because it is company code. I’m hoping someone can lead me to reproduce it as an MRE here. I have a normal jvm project with a unit test. This unit test ends up using this object declaration. During runtime, it throws the exception java.lang.NoSuchFieldError : INSTANCE here: <a class="lightbox"...
View count: 1