Android Kotlin assert list is empty but file is in folder

I am trying to read a file in via Android assets folder. For this I made a assets folder like here. I made a file and it is shows in the explore: When I run in the onCreate method: Log.d("Test", assets.list("/").contentToString()) The output is []. Also when I run: assets.open("Injector.js").bufferedReader().use { Log.d("Test", it.readText()) } The… Read More Android Kotlin assert list is empty but file is in folder

Why does this regex doesn't validate special characters?

Why does the following regex expression in kotlin does not validate special characters? What constitutes as special character? private fun validateSpecialCharacter(password: String): Boolean = password.matches(Regex("[!@#\$%^&*()_+\\-=\\[\\]{};’:\"\\\\|,.<>\\/?]")) >Solution : Using CharSequence.matches(regex) returns True if the entire string matches the regex. Given your code, it looks as if you want your function to return True as long as… Read More Why does this regex doesn't validate special characters?

Kotlin protected var unavailable in Java subclass in different module but same package

I apparently don’t understand Kotlin’s rules of inheritance. In Java, any protected variable would be available in any subclass of the variable’s containing class. In Kotlin, these rules don’t seem to apply. I’m getting a compile error ‘logger’ has private access in com.example.MainActivity. Kotlin code of interest: package com.example.ui abstract class MainActivity : Activity() {… Read More Kotlin protected var unavailable in Java subclass in different module but same package

DataSource configuration

How to optimize setting data source fields when working with multiple datasources? @Bean(name = ["dataSource"]) fun dataSource(): DataSource { val dataSource = DriverManagerDataSource() dataSource.setDriverClassName(driverClassName) dataSource.url = url dataSource.username = username dataSource.password = password return dataSource } Reduce boiler plate code shown above >Solution : It is possible via application.yaml file and little DSL configuration. application.yaml:… Read More DataSource configuration

How to call a `fun func()` without calling a `fun <T> T.func()` with the same name?

I am given a package that has two Kotlin functions named func: a regular fun func() and a generic extension fun <T> T.func(). They have different behaviour, and I’m trying to call fun func(). The problem is, the given scope in which I need to call fun func() has a receiver defined, so fun <T>… Read More How to call a `fun func()` without calling a `fun <T> T.func()` with the same name?

How to translate code with assignment in conditional to Kotlin

I am trying to translate the following code from TypeScript: if (coefficient == -1 && peekToken(/^\(/, tokens)) value = "1" else if (variable = getToken(/^[a-zA-Z]/, tokens)) value = variable; else if (number = getToken(/^(\d*\.\d+)|\d+/, tokens)) value = Number(0 + number); to Kotlin: if (coefficient == -1 && peekToken(Regex("""^\("""), tokens) != null) value = "1" else… Read More How to translate code with assignment in conditional to Kotlin

Why can’t a private method in an interface be declared as final in Java?

In Java 9 and later, we can declare private methods in interfaces. These private methods have a body and are mainly used to implement other methods within the interface or to hide implementation details. This helps to reduce code duplication and encapsulate the implementation of the interface. However, I noticed that private methods in interfaces… Read More Why can’t a private method in an interface be declared as final in Java?