Kotlin, smart cast is impossible because of complex expression

Since mMeshes is a var property, it can change between the assignment of mutableListOf(AiMesh()) and the usage in pScene.mMeshes[0], meaning that it is not guaranteed to be not-null at the use site. The compiler enforces null-safety, treating pScene.mMeshes as nullable MutableList<AiMesh>? and not allowing you to use it as MutableList<AiMesh> (i.e. it cannot safely perform … Read more

What is the purpose of using @field:SerializedName annotation instead of @SerializedName?

TL;DR: The field: part is known as a “use-site target”, and makes it clear that the annotation is applied to the backing field of the Kotlin property. It is not strictly necessary in this case, though it can make the code more readable. Explanation To simplify, let’s say you have: data class Repo( @field:SerializedName(“name”) var … Read more

Why the code in an object expression can access variables from the scope that contains it in kotlin?

In Java, you can only capture (effectively) final variables in anonymous classes and lambdas. In Kotlin, you can capture any variable, even if they are mutable. This is done by wrapping any captured variables in instances of simple wrapper classes. These wrappers just have a single field that contains the captured variables. Since the instances … Read more

Difference between Lock.withLock and synchronized in Kotlin

The extension withLock works on Lock instances like ReentrantLock, whereas synchronized may be used with any object. val lock = ReentrantLock() fun syncWithLockTest(): Int = lock.withLock { 123 } val anyLock = Any() fun syncWithArbitraryObjTest(): Int = synchronized(anyLock) { 123 } Note that synchronized is a function in Kotlin which returns a value. This makes … Read more

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