Categories
Architecture Java Kotlin

Callback styles for async tasks

For asynchronous tasks, the actions on completion need to be handled via a callback. There are different patterns to achieve this, with each having their own benefits and shortcomings. Interfaces One of the oldest callback styles are interfaces or anonymous classes. They are used to great effect in Android. As an example, with okhttp library, […]

Categories
Android Architecture Kotlin testing

Logging in a Java library

It can be useful to emit logs in a library. When doing so, one needs to consider when to emit, how to filter and who is responsible for printing/handling the logs. Correct logging should also be tested. When to log There are different reasons to emit a message, for instance on important events, undefined behaviour […]

Categories
Kotlin

Kotlin: Concatenating nullable strings

A null String is concatenated as “null” in Kotlin: What if the goal is to concatenate only if the second string is not null? There are a few options: if-else One of the solutions would be to check the null value with elvis(?:) operator: Now there is no “null”, but the whole “and second is” […]