https://kotlinlang.org logo
Join Slack
Powered by
# forum
  • r

    rss

    06/30/2025, 1:59 PM
    Google MLKit for ios Has anyone managed to successfully integrate an iOS MLKit into a compose multiplatform project? I have tried everything I can think of to no avail 1 post - 1 participant Read full topic
  • r

    rss

    07/03/2025, 9:59 AM
    .filter after if else if else does not work on first if Greetings! Help me please undestand why this piece of code does not do what I expect it to do. Code snippet class SandboxKtTest { @Test fun test() { val a = 4 val name = if (a < 5) { listOf(3,5,7) } else if (a >5) { listOf(1,2,3) } else { emptyList() }.filter { it == 3 } println(name) } } Expectations: the result is [3] Actual: the result is [3,5,7]. Observations: if i...
  • r

    rss

    07/04/2025, 7:59 AM
    Why does Kotlin allow member and extension function with same signature? Kotlin allows both member functions and extension functions to coexist even if they have the same signature. Why did Kotlin allow this and decide not to show error during compilation? This makes the existing code fragile during dependency updates. 1 post - 1 participant Read full topic
  • r

    rss

    07/06/2025, 12:19 AM
    From Python to Kotlin: Why We Rewrote Our Scraping Framework in Kotlin When it comes to web scraping or browser automation, most people think of Python. We did too. It’s the go-to choice: widely adopted, quick to write, and supported by tons of libraries. But using Python for a large scraping project turned out to be a mistake. What Went Wrong With Python? Although Python seems easy to write, maintaining a large codebase in it was a mess. We constantly ran into issues with typing, like the infamous: 'NoneType' object has no attribute 'xxx' The most painful...
  • r

    rss

    07/07/2025, 2:19 AM
    Throwing runnables and backward compat I have a collection of utilities that I use both from my existing Java code and new Kotlin code. Among those are often utilities that take lambdas. inline fun foo(crossinline lambda : () -> T) : T { [...] return lambda() } When calling from Kotlin this is perfectly fine, because Kotlin does not have checked exceptions. When calling from java, crossinline lambda becomes a Function0. Note the absence of throw clauses. So from Java, I can’t call foo(() -> { if (worldNeedsSaving) {...
  • r

    rss

    07/08/2025, 8:19 AM
    Kotlin Script Execution Not Working in OSGI Environment Hi, I’m working on integrating Kotlin scripting support into an OSGi environment. The project is Maven-based, and I’ve included all the necessary dependencies for .kts script execution. Currently, I’m using a shaded (fat) JAR to package everything, though ideally I’d prefer a more modular or lightweight setup if available. Here’s the current list of dependencies: org.jetbrains.kotlin kotlin-osgi-bundle ${kotlin.version} org.jetbrains.kotlin kotlin-script-runtime...
  • r

    rss

    07/08/2025, 3:19 PM
    No remove Items in ArrayList Hey guys, I’m new to Kotlin and I’m practicing ArrayList. I can’t get it to delete the item I select. Can someone help me? Thanks a lot. package com.example.pruebas.oop.clases import kotlin.String class Producto (val id:String?=“”, val detalle:String?=“”, val pciounit:Double?=0.00, val pciovta:Double?=0.00, val rubro: Int?=0) { val productoArray = ArrayList() fun alta(item: Producto) { productoArray.add(item) } //***********baja fun baja(item:Producto) { if...
  • r

    rss

    07/10/2025, 6:39 AM
    Weird and Unsolvable Exception Hi. While developing an app on Android Studio ( Meerkat Feature Drop | 2024.3.2 Patch 1 ), everything was going fine till today morning when, in order to create a ViewModel and Relevant Factory, I created a class called DataFetchViewModel. And suddenly following error has started to come. I have tried every single possible solution right from clearing caches, updating Android Studio, Repairing IDE, Rescanning indexes and what not. Any Help would be really helpful : kotlin version: 2.0.21...
  • r

    rss

    07/10/2025, 9:59 AM
    What is the safest file format to convert a large JSON file for use in Kotlin (android)? I have a large JSON file that I need to work with in a Kotlin (android) project. Due to its size, I’m considering converting it to a different file format for better performance or easier handling. What would be the safest and most compatible file format to convert this JSON file into, while still being easily readable and usable in Kotlin? Any recommendations or best practices would be appreciated! 1 post - 1 participant <a...
  • r

    rss

    07/11/2025, 1:39 AM
    Project KMP Web doesn´t work in Google Chrome Hi guys, I have a problem in my little project web, well I try to run it in google chrome, but the problem displays this error JsException: Exception was thrown while running JavaScript code kotlinx.coroutines.error_$external_fun@ composeApp.uninstantiated.mjs:187 , in the console. Any suggest or any advice?, or someone has the same problem?. This is my App function: @Composable fun App() { MaterialTheme { var showContent by remember { mutableStateOf(false) } Column( modifier = Modifier...
  • r

    rss

    07/11/2025, 7:59 AM
    What is the roadmap for Kotlin compiler plugins? Hello everyone, we want to use a custom compiler plugin in our company and have to opt in to ExperimentalCompilerApi. The plugin itself is not very complex, so if we need to adjust it later on that would no problem. However, if support for plugins were to be completely dropped, that would be problematic as we intend to build a lot of stuff upon this plugin. Specifially, we are building an IrGenerationExtension that replaces some string templates calls with method calls. Can you say anything...
  • r

    rss

    07/11/2025, 11:49 PM
    Helpme nested lists in map Hello friends, I need to find the content of a map using the key, show the content of the value, and with the same key be able to delete and also modify. I tried with flatmap, but I don’t know how to implement it. package com.example.pruebas.oop.clases import kotlin.String class Producto (val detalle:String?="", val pciounit:Double?=0.00, val pciovta:Double?=0.00, val rubro: Int?=0) { //operator fun component1() = mid val productoMapa = mutableMapOf() val productoArray =...
  • r

    rss

    07/12/2025, 1:29 AM
    Context parameters with `@Composable` functions Can I use the experimental feature of context-parameters (K2.2) with @Composable functions? Can it replace CompositionLocal? I ran a simple small test on a Wasm target, and it seems it works, but I’m not sure about the internals of compose multiplatform 1 post - 1 participant Read full topic
  • r

    rss

    07/12/2025, 9:29 AM
    Using Swing JTable in Kotlin I am moving a Java/Swing app to Kotlin and have run into an issue with JTable. I wish to change the background colour of a cell. The way to do this in Java is to override the DefaultTableCellRenderer function. This is the java code: private class PriceRenderer extends DefaultTableCellRenderer { private static final Border SELECTED_BORDER = new LineBorder(Color.BLUE, 1); private static final Border NO_FOCUS_BORDER = new LineBorder(new Color(0, 0, 0, 0), 1); @Override public...
  • r

    rss

    07/16/2025, 4:39 PM
    How Does Kotlin Lambda Receiver Work as Java Consumer? The assertj library has the java function public static void assertSoftly(Consumer softly) { SoftAssertionsProvider.assertSoftly(SoftAssertions.class, softly); } I noticed accidentally that you can pass a lambda receiver function into this and everything just works… fun assertSoftly(block: SoftAssertions.() -> Unit) { SoftAssertions.assertSoftly(block) // compiles and works } This makes for a much nicer kotlin-friendly experience assertSoftly { assertThat("a").isEqualTo("b") //...
  • r

    rss

    07/18/2025, 7:19 AM
    Kotlin compile sub packages I have a kotlin project that has subpackages. The directory structure is: project —src ------build.xml ------user.properties ------com ---------mainpackage ------------Main.kt ------------subpackage1 ---------------.routine1.kt ------------subpackage2 ---------------routine2.kt I was using Idea Community Edition 2024.1.1 and upgraded to CE 2025.1.3. Since then my ANT compile fails with ‘cannot find subpackage1’ and the same for subpackage2. Has something changed between the 2 versions that...
  • r

    rss

    07/21/2025, 1:19 PM
    Help with exception handling with getValue() I need to get the value of the Map, and handle exceptions, but I can’t find any examples, would someone be so kind? val number = mutableMapOf(1 to "One", 2 to "two", 3 to "three",4 to "four") val nid:Int=0 println(number. getValue(nid)) Exception in thread "main" java.util.NoSuchElementException: Key 0 is missing in the map. 2 posts - 2 participants Read full topic
  • r

    rss

    07/24/2025, 2:39 PM
    How to preserve Context for whole Request with Spring webFlux and coroutines Context: Currently in my web application each request handled by each thread so to store logging context in whole application i use threadLocal which is initialised at start of request and flush logging data & reset at the end of the in request in a filter. But now we have to make a bulk api which simply calls underline service ( this underline service makes network calls) concurrently and combines results. Problem For calling underline service concurrently i’m using coroutines since we...
  • r

    rss

    07/26/2025, 1:19 PM
    Android studio apps making error file///E/SwipupYourfaceapps/app/build.gradle.kts2831: Unresolved reference: VERSION_1_6 1 post - 1 participant Read full topic
  • r

    rss

    07/26/2025, 10:19 PM
    Improved exhaustiveness checks for when expressions with sealed classes in Kotlin 2.1.0 My company code moved finally up to Kotlin 2.1.0 (yay!) and I wanted to give a quick demo of the new features. The else branch in when when it was logically not needed was always bothering me, so I’m glad there is some improvement. However, this seems to work only one level deep: // Kotlin 2.1.0 sealed interface Animal { interface Bird: Animal class Raven: Bird class Hawk: Bird interface Mammal: Animal class Lion: Mammal class Panda: Mammal } fun main() { val...
  • r

    rss

    08/03/2025, 6:29 AM
    Why am I getting "Attempt to invoke virtual method 'java.io.FileInputStream android.content.Context.openFileInput(java.lang.String)' on a null object reference" Hello, I am developing an android application using Android Studios and Kotlin, and for this I made a helper class that helps me save data to an external file and load that data upon startup. This is a snapshot of the function for the loading data: class HelperFunctions { fun getWords(context: Context, wordType: String): MutableList{ return try { Log.d("ContextCheck", "Context is: ${context.javaClass.name}") Log.d("ContextCheck", "${context == null}")...
  • r

    rss

    08/04/2025, 4:09 AM
    Kotlin Playroudn Share code error Hello. I am trying to share Kotlin playground code. However, the issue is the web unable to generate the share link. It seems that this issue is new because several days ago I try to share code via this and it works well. Any idea why? <a class="lightbox" href="

    https://us1.discourse-cdn.com/flex019/uploads/kotlinlang/original/2X/c/cc5f852b8aec219032224ca5ecf53536d6171b3f.png▾

    " data-download-href="/uploads/short-url/t9Y3pBeraP6VqycYH6UnFxGBxj9.png?dl=1" title="image" rel="noopener nofollow...
  • r

    rss

    08/07/2025, 5:19 PM
    How many NoSuchFileException we expected? I create a library to parse object and executable files. When the given file is not exists, I throw the my.NoSuchFileException. I think it’s good, because the file is really not exists. On JVM, since there’s a java.nio.file.NoSuchFileException, so I actual typealias NoSuchFileException = java.nio.file.NoSuchFileException. I think it’s great. The JVM user can keep their styles. On the other platform, I actual it with my class, since there’s no standarized one. But now, I found I make a mess....
  • r

    rss

    08/11/2025, 2:19 PM
    Working with "Any" Variables Help Hi friends, I have a query. I need the returned variable to print details and price term.details term.price but it won’t let me. It prints Product(details=Mouse Usb xxxx, price=3.25) another query. Is it okay to work with Any in this type of function? Thanks package com.example.sys fun main(){ var term:Any=ret() if (term is String) { println("printer:${term}") } else { println("printer:${term}") } } fun ret():Any { data class Product(val details:...
  • r

    rss

    08/12/2025, 3:59 PM
    Let's have an intersection sugar interface Developer { fun develop() } interface BeerExpert { fun drink() } fun doAll(u: T) where T : Developer, T : BeerExpert { u.develop() u.drink() } // I wish that could be written as fun doAll(u: Developer & BeerExpert) { u.develop() u.drink() } Inspiration: Handbook - Unions and Intersection Types 1 post - 1 participant <a...
  • r

    rss

    08/13/2025, 4:19 PM
    listOf get index numbers I am following this tutorial

    here▾

    . class MainActivity : ComponentActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) enableEdgeToEdge() val people = listOf("John", "Jack", "DJ", "Luke", "Matt", "Andrew", "Dave", "Steven", "Billy", "Zane", "Bobby", "Ryan", "Martin", "Werner", "Peter") setContent { RSSReaderTheme...
  • r

    rss

    08/13/2025, 10:19 PM
    A new feature for default arguments Hello! Image a function that has a default argument. Is there a way to call this function with a certain argument if a condition is met, else use the default argument? Here’s some code: fun foo(arg: String = "Default value”) { … } fun main() { foo( arg = if (...) "My value" else default() // I'm inventing here a default function (a possible new feature, which of course can also be made in other ways) which calls the function with its default argument! ) } Here, the default argument is...
  • r

    rss

    08/17/2025, 11:19 AM
    Why does my Kotlin Android app crash when using coroutines in ViewModel? Hello I am developing an Android app in Kotlin and recently added coroutines to handle background tasks in my ViewModel. The issue is that when the screen rotates or the activity is recreated; the app sometimes crashes with JobCancellationException / other lifecycle-related errors. I expected the ViewModel scope to manage this automatically but it seems like my coroutines are still being cancelled unexpectedly. I tried using viewModelScope.launch as recommended & also tested with...
  • r

    rss

    08/21/2025, 7:59 PM
    New(?) idea for collection literals Typing this out from my phone so I haven’t tested the idea thoroughly but thought the idea maybe spark a good discussion. Collection literals will only be available when there is a “CollectionBuilder” in context. For example: fun interface ListBuilder { operator fun buildList(varargs elements: I): T } This would allow code looking something like this: val list = with(ArrayListBuilder) { [1, 2, 3] } Of course, Kotlin let’s us bring things into context in a lot of ways...
  • r

    rss

    08/28/2025, 3:09 PM
    Deconstruction with * operator, similar to vararg I often want to call functions with an object, but I need to specifiy the parameters explicitly: class Circle(val centerX: Int, val centerY: Int, val radius: Float) val point = IntOffset(100,200) val circle = Circle(point.width, point.height, 70f) but I’d like to avoid writing .width .height all over my code. I suggest to do this: val circle = Circle(*point, 70f) This is very similar to how * operator works for the vararg, and it seems natural to me. What do you think? 1...