Jooq fetchInto with default value if field is null

The reason is that JSON_ARRAYAGG() (like most aggregate functions) produces NULL for empty sets, instead of a more “reasonable” empty []. Clearly, you never want this behaviour. So, you could use COALESCE, instead, see also this question: coalesce( jsonArrayAgg(jsonObject(book.ID, book.PRICE)), jsonArray() ) I’ll make sure to update all the other answers I’ve given on Stack … Read more

Kotlin and Immutable Collections?

Kotlin’s List from the standard library is readonly: interface List<out E> : Collection<E> (source) A generic ordered collection of elements. Methods in this interface support only read-only access to the list; read/write access is supported through the MutableList interface. Parameters E – the type of elements contained in the list. As mentioned, there is also … Read more

Single exclamation mark in Kotlin

They’re called platform types and they mean that Kotlin doesn’t know whether that value can or cannot be null and it’s up to you to decide if it’s nullable or not. In a nutshell, the problem is that any reference coming from Java may be null, and Kotlin, being null-safe by design, forced the user … Read more

What is a “receiver” in Kotlin?

It is true that there appears to be little existing documentation for the concept of receivers (only a small side note related to extension functions), which is surprising given: their existence springing out of extension functions; their role in building a DSL using said extension functions; the existence of a standard library function with, which … Read more

Smart cast to ‘Type’ is impossible, because ‘variable’ is a mutable property that could have been changed by this time

Between execution of left != null and queue.add(left) another thread could have changed the value of left to null. To work around this you have several options. Here are some: Use a local variable with smart cast: val node = left if (node != null) { queue.add(node) } Use a safe call such as one … Read more

tech