/r/Kotlin
Discussion about Kotlin, a statically typed programming language for the JVM, Android, JavaScript, and native.
Kotlin is a statically typed programming language for the JVM, Android, JavaScript, and native.
Related subreddits:
Resources:
/r/Kotlin
Hi! I’ve created a Kotlin REPL for the terminal with support for multiline code editing, interconnected cells, code completion, and error highlighting.
Source code/installation: https://github.com/darthorimar/rekot
I'm learning flows and an trying to wrap my head around how I should be combining two flows properly. I feel like i'm overcomplicating this and help would be appreciated.
The following code has two flows, one is a list of groups and the other is a preferred group id that's coming from a preferences datastore. I want to update the "myGroup" value whenever the group list OR the preferred id changes. Is the following the correct way?
There's a flow of <Int?> and then a flow of "Array<Group>". I need "myGroup" to update when either of the flows emit:
`
private val _allGroups = MutableStateFlow<Array<Group>>(emptyArray())
private val _myGroup = MutableStateFlow<Group?>(null)
private val _myGroupId: Flow<Int?> = prefs.data.map{it[UserPrefs.myGroupId]}
//when group id changes in preferences OR _allGroups changes, retrieve group
val myGroup = _myGroupId.map {
groupId -> _allGroups.value.firstOrNull{it.id == groupId}
}
init {
viewModelScope.launch {
//load all of the groups
someOutsideGetGroupsFlow().collect{
_allGroups.value = it
}
}
`
Kotools Samples 0.2.0 is out with the support of samples from the test
Kotlin source set, Gradle 8.11.1 and much more. 🎉
Kotools Samples is a Gradle plugin that inlines read-only Kotlin and Java code samples into Dokka documentation, ensuring they are always correct and visible not only online but also in IDEs. It addresses a limitation in Dokka, which does not allow making code samples non-editable or non-executable. 📚✨
Star and watch our GitHub repo to stay updated for future support of Kotlin Multiplatform projects! ⭐
I'm looking to create a timer app that syncs over the network with other instances of the app. What would be the best way of doing this?
The original app was made in python and was using webstockets but I'm interested if there's a kotlin library that could provide data syncing without manually writing the ws implementation
What tool should I use for not microbenchmarking? For example in my process I go to the database and send to the kafka. Is it right to use JMH or there's another tool? Maybe just usemeasureTimeMillis.
Hey, did anyone try to setup full stack with Kotlin on backend and typescript on frontend, while automatically generating typescript types from kotlin?
My idea is to have ktor backend, shared project where I define kotlin shared types which would be transpiled into typescrip types and then fronted projects that can use shared typescript definitions. It'd prefer to do it on each save of shared kotlin code, so that dev experience is as smooth as possible.
I like to listen to audio stuff when solo: driving, walking around stores, etc. and I'm wondering if there are any informative shows, podcasts, etc. about kotlin that are audio only/first that exist.
YouTube videos exist, but often (always?) assume you can see the screen, and content without any screen components would be great when driving, etc.
Anyone have experience in using both? Copilot I found was great when I used it a year ago. Don't have experience with JetbrainsAI assistant.
Do you have a strong opinion of one over the other?
Edit: If you don't have experience with LLM inside IDEs, your feedback is not helpful. We don't need to know that you don't know.
I am new to kotlin and i want the best resources online for free to start learning
So im using GDLauncher to run an instance of minecraft,v1.21.1 Fabric to be more specific and some of my mods require as a dependency the mod Fabric Language Kotlin but i keep getting the error ( java.lang.RuntimeException: Failed to instantiate language adapter: kotlin ) !Here is the link to the full logs >!<.If someone can point the problem and hopefully a solution it would be fantastic because im stuck !
Hi
I wanted to ask for an advice with my problem. I'm running self-hosted github action runner which runs all the tests.
There are plenty integration tests using kafka, some redis with testcontainers. The issue i'm experiencing is `Exception: java.lang.OutOfMemoryError` in the middle of the tests (on local machine all works fine). I'm trying to debug/figure out how to fix it.
Some background.
Self hosted runner is on k8s. Pod itself has 10g ram available, process is not killed by k8s, thus i assume it is enough. When running `kubectl top pod` i noticed, that github runner reach maximum 7000m than `Exception: java.lang.OutOfMemoryError` error occur. What could be the reason? Tests are run by gradle - changing org.gradle.jvmargs had no effect, Xmx4g or Xmx6g all resulted in OOM error when pod hit 7000m.
Read testcontainers docs, but no much help, it theory it should consume all the memory available.
Is there anything which is preventing to allocate more than 7000m for tests?
Hi everyone,
I'm using HikariCP in my kotlin-project and imported it via gradle. So far so good, everything seems to be good when running it within my IntelliJ IDEA, but as soon as I run my JAR within a docker container, there is a lot of DEBUG-output from Hikari.
I've tried a lot, googled and tested many settings but I was not able to get rid of these debug-messages. Can someone please shed any light on it? Also, I would be very curious to understand why that only happens within the production-environment and not within IntellliJ...
Thanks!
Hi Folks,
I got 20+ years of experience with Java and started doing full time Kotlin 2 years ago. The transition was (still is) pretty smooth and exciting.
Reflecting on my experience with writing Kotlin in various projects, I have come to realize I'm very reluctant to use nullable types in my code. Searching the 100K SLOC I wrote and maintain, I have only come across a handfull of nullable type declarations. Both in parameters types and in value & variable declarations.
Out of experience, it's usually fairly simple to replace
var foobar: Type? = null
with non-nullable counter part val foobar: Type = ...
My main motivation to do this is that I see more value is eliminating NULL from my code base rather than explicitely having to deal with it and having safe call operators everywhere.
I'ld even prefer a lateinit var
over a nullable var.
Now I wonder how other experienced Kotlin developers work with (work around or embrace) nullable types. Am I overdoing things here?
Appreciate your feedback.
I’ve been a JetBrains fan for many years, and, full disclosure, they give me free access to their tools as a Google Developer Expert.
Recently though, fellow GDE and author Uberto Barbini has been writing Kotlin not in IntelliJ, but using the Cursor - The AI Code Editor. Based on VSCode, what Cursor lacks in specific Kotlin support it makes up for with fantastic LLM integration.
So today I’m pairing with Uberto; or rather, talking to him while he pairs with Cursor.
In this video, Duncan, a long-time JetBrains fan, collaborates with Uberto, a fellow Google Developer Expert, to explore using Cursor, a VS Code-based code editor, for coding in Kotlin with powerful integration of Large Language Models (LLMs). They discuss Uberto's experience of performing test-driven development (TDD) using Cursor, which automates many coding tasks. Despite some issues such as minor coding errors and inconsistent results, both found significant productivity benefits. They use Cursor to develop an algorithm for a modified FizzBuzz problem. The session concludes with a plan to revisit their process with more granular TDD steps, showing both optimism and acknowledgment of the tool's current limitations.
There is a playlist of AI episodes - https://www.youtube.com/playlist?list=PL1ssMPpyqociSAO5NlyMEYPL6a9eP5xte
If you are going to be at KotlinConf 2025, or even just in Copenhagen in May, then you should sign up for the workshop that Nat Pryce and I are running. It’s called Refactoring to Functional Kotlin, and will give you hands-on experience of taking legacy code and safely migrating it to a functional style. Places are limited, so buy now at https://kotlinconf.com/workhops
I get lots of questions about the test progress bar. It was written by the inimitable @dmitrykandalov. To use it install his Liveplugin (https://plugins.jetbrains.com/plugin/7282-liveplugin) and then this gist https://gist.github.com/dmcg/1f56ac398ef033c6b62c82824a15894b
Uberto's prompt preamble for Cursor can be found at https://github.com/uberto/cursorutils/blob/main/functional_kotlin_rules
If you like this video, you’ll probably like my book Java to Kotlin, A Refactoring Guidebook (http://java-to-kotlin.dev). It's about far more than just the syntax differences between the languages - it shows how to upgrade your thinking to a more functional style. And check out Uberto's book, From Objects to Functions https://pragprog.com/titles/uboop/from-objects-to-functions/
Java, Speing, play framework, Angular, do you think Kotlin is a good to learn ?
Will it give a job that pays well ?
I am learning distrubution, SQL, webpage, Serlvet, oracle and MVC. Why will I choise an new langage instead of Java ?
Hey r/Kotlin! 👋
I'm back with the second article in my Kotlin: The Learning Journey series! After exploring Gradle Version Catalogs, this time, we’re diving into a fantastic library that makes generating random values for test cases easier and more powerful: KotlinFixtures.
🔍 What’s KotlinFixtures?
Created by Matthew Dolan, KotlinFixtures helps you generate well-defined yet random input values for your classes, following the idea of constrained non-determinism. It’s a great tool for writing cleaner, more maintainable, and flexible test cases.
🎯 What you’ll learn in this article:
✅ How to integrate KotlinFixtures into your project
✅ How to customize your inputs
✅ How to create test scenarios efficiently
🔗 Read it here: Kotlin: The Learning Journey — Path 2: Kotlin Fixtures | by Yan Tapajós | Jan, 2025 | Medium
Let’s chat!
💬 Have you used KotlinFixtures before? What’s your experience?
🤔 What other testing utilities do you use in Kotlin?
📢 What topics would you like me to cover next?
May the Kotlin be with you! 🌌✨
#Kotlin #KotlinServerSide #BackendDevelopment
JetBrains has updated the Ktor generator with:
Give it a try and enjoy seamless Ktor development. 👉 https://start.ktor.io/settings
I'm dealing with a shared resource which can be used by multiple Coroutines at the same time. Let's say this shared resource is this function: suspend fun longRunningResource(): Result
Coroutine #1 and Coroutine #2 now want to access the function at the same time. Obviously, with a Mutex (Mutual exclusion), Coroutine #1 can enter the shared resource and lock it for Coroutine #2. Once Coroutine #1 is finished, it is unlocked and Coroutine #2 can access it.
However, for my use-case it makes more sense like this:
suspend fun longRunningResource(): Result
-> Basically, although two Coroutines access it,longRunningResource()
runs only once and both Coroutines receive the same result.
Does this concept have a name? ("Mutin" for Mutual inclusion? 😄)
Please note: I'm not asking for any code samples. I have a working snippet already (which I can share if you are interested), but I wonder if something like this already exists and I am just looking for the wrong keywords.
I'm building my first backend with Ktor and have come across many resources recommending AWS and App Engine. However, I feel that the pricing is quite high, especially since I’m using a PostgreSQL database.
Would Railway/PostgreSQL be a good option to start with?
Hello, would any of you like to use Kotlin to program or maybe learn how to do it?
I personally like Kotlin a lot but I haven't delved into it, and although I previously learned algorithmic logic with C++, I would like to refresh it, improve it and master DSA. Maybe using Kotlin is a good start
Would anyone like us to dedicate ourselves to this mini project together?
I would like to find someone to motivate me in the process!!
Is there any trick to handling imports for kotlin with IDEA/Android Studio? I'm considering abandoning Intellij, which I generally love, which I would do in a heartbeat if I knew something better. The default experience for imports is to just let them be discovered on the fly, which happens 5 seconds after you type the identifier, so the cursor is not on the identifier, and every keypress causes it to re-evaluate and you must stop everything for a time to try and catch the pop up which is an awful user-experience.
You could enable the "Add unambiguous imports on the fly" option but that will 1 times out of 100 give you the wrong import which can take a lot of frustration to figure out when it comes back to haunt you several hours later and you have to retrace your steps. That is a dealbreaker without the "optimize imports on the fly" option which takes away any lines that you added manually. Even something as simple as renaming the file (even without that option enabled) will take away the imports you added manually.
And then there are the cases when whatever discovers the imports just can't even at the moment and there is a viable import that it just doesn't detect, and after questioning every life decision you've made until now you hopefully sherlock it out on your own. This is easily the worst aspect to kotlin in IDEA IDEs at the moment, at least for me. Am I missing something?
Do you use Kotlin for backend development?
We’re launching the Kotlin for Server-Side Content Creators campaign to recognize good content and share it with the Kotlin community. Whether it’s a blog post, video, or project, we want to promote your work.
What to share?
Learn more: https://kotl.in/mme5xl
Hi Exposed-pros,
I'm having funA() handling db-operations within a transaction-block.
Now there is a funB() which does a different db-task, also within a transaction-block. Sometimes, funA calls funB() as well and now there are two transaction blocks called. Is that a problem or does exposed recognize it and uses only the first transaction? Thanks!