In python, I can write a trace function like: and it’d print the recursive trace for any general recursive function beautifully: Is it possible to write a simple similar one in Java/Kotlin? Or is it only doable with AOP or the like? Answer EDIT: formatting does not 100% match yours, but that is easily f…
Tag: kotlin
how to clean up generated data binding files?
I’ve got a problem I created the activity and xml files in a git branch. Commit these tasks, and change the branch to do something else. However, when build app, the following error occurred. ActivityDebugUserInfo is the file I created in the previous branch. There is no such file in the current branch.…
Kotlin JNA getting declared field names to be empty list
The code below is highly inspired by this answer and this answer, and I am trying to get it work with Kotlin language, rather than Java that was given in the answer there. It is basically based on JNA (Java Native Access), which essentially pulls the SYSTEM_BATTERY_STATE from the Windows Native library (on C+…
lateinit property mock object has not been initialized
I’m trying to initialize (by mocking) two objects with the annotation @MockBean It seems only to work if i call the method mock(className), but since i want to use the mocked class on multiple methods i don’t want to keep repeating the same code in my test methods. This is my test class: I donR…
onCreateOptionsMenu not being called
onCreateOptionsMenu does not get called in a fragment. I have to manually call setHasOptionsMenu(true) in onCreatedView() but this causes the item.itemId be an empty String “” in the onOptionsItemSelected() and therefore i can’t detect which menu item was tapped. I’m currently using th…
Caffeine: Use stale values when AsyncLoader fails to refresh
I want to configure my Caffeine cache to return stale results when loader fails to refresh the cache. The following Kotlin code demonstrates the case: I expect this test to pass but instead I get the following error: I wrote the code in Kotlin but I don’t think the issue is related to Kotlin coroutines.…
Using Java Optional in Kotlin DTOs
Currently I’m using Java 8’s Optional in my Kotlin DTOs as follows: The purpose of it is that for some properties like prop2 I want to also allow delete in the request. So the value of prop2 in the DTO is understood as follows: null => do nothing non-empty optional => update value empty opti…
Gradle project builds successfully but IntelliJ cannot resolve references
Every usage of the following Kotlin library compiles and can be used, but IntelliJ’s autocomplete (and perhaps others) cannot resolve the references. https://gitlab.com/7Hazard/altv-kotlin I am using it as a dependency via JitPack: https://jitpack.io/#com.gitlab.7Hazard/altv-kotlin JDK 11, Gradle 6.3 (w…
Migrate an existing app in playstore from java to kotlin
this is more a theoretical question. I have an app that is already in the playstore. This app has been working since the year 2017, so it has a lot of old libraries. The goal is to migrate it to kotlin. So, what’s more effective to achive this goal: Migrate file by file to kotlin Create a new project wi…
How to build cordova project with Kotlin
I have a cordova project folder www already in progress. Build this and you will have an Android project. This will create a MainActivity.java file. I don’t know Java so I changed the file to MainActivity.kt and converted the internal code. But when I run it, it doesn’t run as error. Build cordova…