Category "kotlin"

Invoke Operator & Operator Overloading in Kotlin

I get to know about the Invoke operator that, a() is equivalent to a.invoke() Is there anything more regarding Invoke operator than please explain. Also, I did

Default value for injection parameter

A simplified example: I have the following Koin module: val testModule = { factory<User> { (name: String) -> User(name) } } The Use

What's the difference between .kt and .kts files in Kotlin. When should we use .kts file over .kt file?

What is the purpose of using .kts files in Kotlin? Are these files included in the app bundle when releasing the app?

How to map a JSON string to Kotlin Map

I have a simple Kotlin program that access a Mongo database and produce a JSON string as below; "{ "_id" : { "$oid" : "593440eb7fa580d99d1abe85"} ,

Convert indefinitely running Runnable from java to kotlin

I have some code like this in java that monitors a certain file: private Handler mHandler = new Handler(); private final Runnable monitor = new Runnable() {

Android Studio is giving errors and warnings after enabling view binding. How to fix?

I am getting errors after i enabled view binding in my project. I have tried resyncing the project, invalidating cache. My app gradle file: apply plugin: 'com

CardView remove border

I want too remove a border on my cardView. I try set elavation to 0 dp , app:cardPreventCornerOverlap to false and app:cardUseCompatPadding to true , but I can

Room Persistence: Error:Entities and Pojos must have a usable public constructor

I'm converting a project to Kotlin and I'm trying to make my model (which is also my entity) a data class I intend to use Moshi to convert the JSON responses fr

Overload equals of BigDecimal in Kotlin

In a Kotlin file I try to overload the equals method of the BigDecimal class. I have the following piece of code for that: fun BigDecimal.equals(n: Any?): Bool

assign variable only if it is null

on Ruby one have something like this: @var ||= 'value' basically, it means that @var will be assigned 'value' only if @var is not assigned yet (e.g. if @var

Gradle 6+ : compile groovy before kotlin

I'm working on a project combining groovy and kotlin. My Kotlin classes require objects from groovy part, how can i make gradle compile groovy before kotlin ?

kotlin dotenv doesn't take directory configuration

Trying to use kotlin-dotnet, but this is not working, using kotlin object class, to manage singleton Got error Could not find /asset/env on the classpath where

Android Jetpack DataStore Fatal Exception: java.io.IOException

Im using datastore in one of my android library and I get crashes from google vitals that I cant reproduce and should not be possible... I create my datastore a

how to use Coroutine in kotlin to call a function every second

i just created an app where my function getdata() call every second to fetch new data from server and updateui() function will update view in UI i don't use any

Is there a way to filter out null Any? values in Kotlin Map?

I'm trying to think of a function that would allow a Map<String, Any?> object to be treated as Map<String,Any> through type inference through applyi

FragmentFirstBinding Error with First Fragment XML Changes

I'm in Bumblebee v.2021.1.1. I don't have any database elements in my project. I do have defaults in the first fragment: import com.my.app.databinding.FragmentF

How to create a fat JAR with Gradle Kotlin script?

As titled, I'd like to know how to modify the gradle.build.kts in order to have a task to create a unique jar with all the dependencies (kotlin lib included) in

Jetpack Compose + Hilt: java.lang.RuntimeException: Cannot create an instance of class ViewModel

I started trying jetpack Compose recently and used hilt & hilt-navigation-compose for my app. It works fine with the first ViewModel. However, when I try th

No matching client found for package name "...." with different buildvariant

I want o implement push notification. I added to project level: dependencies { classpath 'com.android.tools.build:gradle:2.2.2' classpath 'com.

Modules that need to be instantiated by Hilt must have a visible, empty constructor

@Module @InstallIn(SingletonComponent::class) class WheelModule constructor(val size:Int) { @Provides fun provideWheel():Wheel = Wheel(size) } Module