All Blogs
crossinline in Kotlin
crossinline in Kotlin is used to avoid non-local returns from a lambda that is passed to an inline function. We will learn it with a simple example.
inline function in Kotlin
An inline function in Kotlin tells the compiler to insert the complete body of the function wherever that function is called, which avoids the call overhead.
noinline in Kotlin
noinline in Kotlin is used when we do not want all the lambdas passed to an inline function to be inlined. We mark those lambda parameters as noinline.
Use setRecycledViewPool for Optimizing Nested RecyclerView
setRecycledViewPool lets the inner RecyclerViews of a Nested RecyclerView share one view pool, so that views get reused and scrolling becomes smooth.
singleTask launchMode in Android
With singleTask launchMode, only one instance of the Activity exists at a time. If it already exists, its Task is brought forward and it gets the new intent.
init block in Kotlin
The init block in Kotlin runs when an object is created, right after the primary constructor, and lets us write the initialization code that it cannot hold.
Companion object in Kotlin
A companion object in Kotlin lets us call a function or access a property using the class name, without creating an object, like static in Java.
lateinit vs lazy in Kotlin
In Kotlin, lateinit is used with var when we will initialize the variable later, whereas lazy is used with val to create the object only on its first access.
Infix notation in Kotlin
Infix notation in Kotlin lets us call a function without the dot and parentheses, so that the code looks much more like a natural language.