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 use jackson to deserialize to Kotlin collections

With Jackson Kotlin Module current versions, if you import the full module package or the specific extension function you’ll have all extension methods available. Such as: import com.fasterxml.jackson.module.kotlin.* val JSON = jacksonObjectMapper() // keep around and re-use val myList: List<String> = JSON.readValue(“””[“a”,”b”,”c”]”””) Therefore the Jackson Module for Kotlin will infer the the correct type and … Read more

Jetpack Compose collapsing toolbar

Jetpack Compose implementation of Material Design 3 includes 4 types of Top App Bars ( CenterAlignedTopAppBar SmallTopAppBar MediumTopAppBar LargeTopAppBar They all have a scrollBehavior parameter, which can be used for collapsing the toolbar. There are 3 basic types of scroll behavior in the library: TopAppBarDefaults.pinnedScrollBehavior TopAppBarDefaults.enterAlwaysScrollBehavior TopAppBarDefaults.exitUntilCollapsedScrollBehavior Note: This API is annotated as … Read more

Kotlin Annotation IntDef

Strange thing, but this question comes in search before the same with right answer Copying it here: import public class Test { companion object { @IntDef(SLOW, NORMAL, FAST) @Retention(AnnotationRetention.SOURCE) annotation class Speed const val SLOW = 0 const val NORMAL = 1 const val FAST = 2 } @Speed private var speed: Int=SLOW public … Read more

How to set up Kotlin’s byte code version in Gradle project to Java 8?

As Mark pointed out on Debop’s answer, you have to configure both compileKotlin and compileTestKotlin. You can do it without duplication this way: tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all { kotlinOptions { jvmTarget = “1.8” } } For a pure Kotlin project, I don’t think the options sourceCompatibility and targetCompatibility do anything, so you may be able to remove them. … Read more

Android Studio quick documentation always “fetching documentation”

The problem is Android Studio does not automatically update the source link of reference even when the documentation is already downloaded. The default link in jdk.table.xml is (android studio tries to connect to this online server even if the network is blocked). To solve the problem, we can just redirect the reference to local … Read more

Existing 3-function callback to Kotlin Coroutines

In this particular case you can use a general approach to convert a callback-based API to a suspending function via suspendCoroutine function: suspend fun CameraManager.openCamera(cameraId: String): CameraDevice? = suspendCoroutine { cont -> val callback = object : CameraDevice.StateCallback() { override fun onOpened(camera: CameraDevice) { cont.resume(camera) } override fun onDisconnected(camera: CameraDevice) { cont.resume(null) } override fun … Read more