how to run compiled class file in Kotlin?

Knowing the Name of Your Main Class Currently (Kotlin since M14 including up to 1.0 betas), to run a Kotlin class you are actually running a special class that is created at the file level that hold your main() and other functions that are top-level (outside of a class or interface). So if your code … Read more

How to convert String to Int in Kotlin?

You could call toInt() on your String instances: fun main(args: Array<String>) { for (str in args) { try { val parsedInt = str.toInt() println(“The parsed int is $parsedInt”) } catch (nfe: NumberFormatException) { // not a valid int } } } Or toIntOrNull() as an alternative: for (str in args) { val parsedInt = str.toIntOrNull() … Read more

How to create a fat JAR with Gradle Kotlin script?

Here is a version that does not use a plugin, more like the Groovy version. import org.gradle.jvm.tasks.Jar val fatJar = task(“fatJar”, type = Jar::class) { baseName = “${project.name}-fat” manifest { attributes[“Implementation-Title”] = “Gradle Jar File Example” attributes[“Implementation-Version”] = version attributes[“Main-Class”] = “com.mkyong.DateUtils” } from(configurations.runtime.map({ if (it.isDirectory) it else zipTree(it) })) with(tasks[“jar”] as CopySpec) } tasks … Read more

How can I detect a click with the view behind a Jetpack Compose Button?

When button finds tap event, it marks it as consumed, which prevents other views from receiving it. This is done with consumeDownChange(), you can see detectTapAndPress method where this is done with Button here To override the default behaviour, you had to reimplement some of gesture tracking. List of changes comparing to system detectTapAndPress: I … Read more

Multiple variable let in Kotlin

Here are a few variations, depending on what style you will want to use, if you have everything of same or different types, and if the list unknown number of items… Mixed types, all must not be null to calculate a new value For mixed types you could build a series of functions for each … Read more