Questions
Kotlin questions
Choose a question page, learn the concept, then test your understanding with a quiz.
Kotlin Constants: Recommended Ways to Declare and Name Them
Learn how to create constants in Kotlin, when to use const val vs val, and the standard naming conventions with clear examples.
Kotlin Data Class Default Constructor and Optional Parameters in Android
Learn how to create an empty-like constructor for a Kotlin data class using default parameter values in Android.
Kotlin Double-Bang Operator (!!): Meaning, Null Safety, and Safer Alternatives
Learn what Kotlin's !! operator means, when it throws NullPointerException, and which safer null-handling options to use instead.
Kotlin Equivalent of Java String[]: Arrays of Strings Explained
Learn the Kotlin equivalent of Java String[] and understand Array<String>, primitive arrays, syntax, examples, mistakes, and usage.
Kotlin JUnit @Rule Visibility with ActivityTestRule in Android Tests
Learn why Kotlin JUnit @Rule fields fail visibility checks in ActivityTestRule tests and how to fix them with @JvmField.
Kotlin Property Initialization: by lazy vs lateinit
Learn when to use Kotlin by lazy or lateinit for property initialization, with examples, differences, mistakes, and practical guidance.
Kotlin Public Getter Private Setter for var: How Accessors Work
Learn how to declare a Kotlin var with a public getter and private setter, with syntax, examples, mistakes, and real use cases.
Kotlin String Formatting: Format Numbers in String Templates
Learn how to format numbers in Kotlin string templates, including limiting decimal places for Double values with practical examples.
Kotlin Ternary Conditional Operator Equivalent Explained
Learn the Kotlin equivalent of the ternary conditional operator and how to use if as an expression with clear examples.
Kotlin const vs val: What’s the Difference?
Learn the difference between const and val in Kotlin, when to use each, and common mistakes with clear examples.
Kotlin switch-case Equivalent: Using when Expression
Learn how to replace Java switch-case in Kotlin using when, with syntax, examples, common mistakes, and real-world usage.
Passing Functions as Parameters in Kotlin
Learn how to pass a function as a parameter in Kotlin using function references, lambdas, and matching function types.
Room Persistence Library Auto-Increment Primary Key in Kotlin
Learn how to create an auto-increment primary key in Room using Kotlin, with @PrimaryKey(autoGenerate = true) examples and common mistakes.
Sort by Multiple Fields in Kotlin: sortedBy, thenBy, and compareBy
Learn how to sort a list by multiple fields in Kotlin using compareBy, thenBy, and sortedWith with clear examples and common pitfalls.
Swift `if let` Equivalent in Kotlin: Safe Null Handling with `let`, `?.`, and `if`
Learn the Kotlin equivalent of Swift `if let` for nullable values using safe calls, `let`, Elvis, and null checks with clear examples.
Understanding the Kotlin Plugin Version Warning in Gradle for Android and Java Modules
Learn why Android Studio shows a Kotlin plugin version warning in Gradle, even when versions match, and how to handle it correctly.
What `suspend` Means in Kotlin Coroutines
Learn what `suspend` means in Kotlin coroutines, which coroutine is suspended, and how suspension differs from blocking threads.
What the `by` Keyword Does in Kotlin: Delegated Properties Explained
Learn what the `by` keyword means in Kotlin, especially for delegated properties in Android and Kotlin apps, with examples and common mistakes.
What to Use Instead of Deprecated Handler() in Android Kotlin
Learn why Handler() is deprecated in Android Kotlin and how to replace it with Handler(Looper), coroutines, or view.postDelayed().
Why Kotlin Smart Cast Fails on Mutable Properties: var, Null Safety, and Elegant Fixes
Learn why Kotlin smart cast fails on mutable properties and how to fix it safely using local vals, safe calls, and null handling.