Kotlin and new ActivityTestRule : The @Rule must be public

JUnit allows providing rules through a test class field or a getter method. What you annotated is in Kotlin a property though, which JUnit won’t recognize. Here are the possible ways to specify a JUnit rule in Kotlin: Through an annotated getter method From M13, the annotation processor supports annotation targets. When you write @Rule … Read more

Extend data class in Kotlin

The truth is: data classes do not play too well with inheritance. We are considering prohibiting or severely restricting inheritance of data classes. For example, it’s known that there’s no way to implement equals() correctly in a hierarchy on non-abstract classes. So, all I can offer: don’t use inheritance with data classes.

Constants in Kotlin — what’s a recommended way to create them?

Avoid using companion objects. Behind the hood, getter and setter instance methods are created for the fields to be accessible. Calling instance methods is technically more expensive than calling static methods. public class DbConstants { companion object { val TABLE_USER_ATTRIBUTE_EMPID = “_id” val TABLE_USER_ATTRIBUTE_DATA = “data” } Instead define the constants in object. Recommended practice … Read more

A failure occurred while executing org.jetbrains.kotlin.gradle.internal.KaptExecution

Android Studio’s UI was just hiding the error… when the error occurred, it highlighted the item in the list view, and showed an unhelpful message in the terminal view. to find the real error, select the root item in the list view so that Android Studio would display the whole build output in the terminal … Read more

How do I initialize Kotlin’s MutableList to empty MutableList?

You can simply write: val mutableList = mutableListOf<Kolory>() This is the most idiomatic way. Alternative ways are val mutableList : MutableList<Kolory> = arrayListOf() or val mutableList : MutableList<Kolory> = ArrayList() This is exploiting the fact that java types like ArrayList are implicitly implementing the type MutableList via a compiler trick.

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)