Skip to content
tezvyn:

All bites

The whole library, newest first. Filter by what you are here for, or pick a topic if you already know.

4330 bites

Page 192

Explain val vs var in Kotlin and null safety risks
Android & Kotlin2 min read

Explain val vs var in Kotlin and null safety risks

Val is read-only, var is mutable; nullables use ? like String?; risk is NullPointerException if checks are missed.

Explain val vs. var and null safety in Kotlin
Android & Kotlin2 min read

Explain val vs. var and null safety in Kotlin

Tests your grasp of Kotlin's core principles: immutability and compile-time null safety. Define val (read-only) vs. var (mutable), declare nullables with ?, and identify the risk as runtime NullPointerExceptions.

Explain val, var, and null safety in Kotlin
Android & Kotlin2 min read

Explain val, var, and null safety in Kotlin

This tests your grasp of immutability and Kotlin's compile-time null safety. Define val (immutable reference) vs. var (mutable), explain nullable types using ?, and state the risk is NullPointerException. A red flag is confusing val with a constant.

What do the safe call and Elvis operators do in Kotlin?
Android & Kotlin2 min read

What do the safe call and Elvis operators do in Kotlin?

?. yields null if receiver is null; ?: provides the right operand when left is null; chain as val len = str?.length ?: 0.

Purpose of Kotlin's safe call (`?.`) and Elvis (`?:`) operators?
Android & Kotlin2 min read

Purpose of Kotlin's safe call (`?.`) and Elvis (`?:`) operators?

This tests your grasp of Kotlin's null safety philosophy. A good answer defines the safe call (?.) for conditional access and the Elvis operator (?:) for default values, then combines them. A red flag is using verbose if/else checks for simple cases.

Purpose of safe call (`?.`) and Elvis (`?:`) operators
Android & Kotlin2 min read

Purpose of safe call (`?.`) and Elvis (`?:`) operators

This tests your grasp of Kotlin's idiomatic null safety. Explain the safe call (?.) for chaining on nullables and the Elvis operator (?:) for providing defaults. Combine them in a one-line example. A multi-line if/else is a red flag.

What is an extension function? Write a hasWhitespace extension for String.
Android & Kotlin2 min read

What is an extension function? Write a hasWhitespace extension for String.

Explain receiverType.functionName adds behavior without inheritance; write hasWhitespace with any { it.isWhitespace() }.

What is a Kotlin extension function? Write one for String.
Android & Kotlin2 min read

What is a Kotlin extension function? Write one for String.

Tests your grasp of adding functionality to existing classes without inheritance. A great answer defines it as syntactic sugar over static methods, explains its use for third-party code, then implements the requested String.hasWhitespace function.

What is a Kotlin extension function? Write one for String.
Android & Kotlin2 min read

What is a Kotlin extension function? Write one for String.

Tests adding functionality to classes without inheritance. Define extension functions as static utilities, explain their use case (e.g., third-party libs), then write hasWhitespace using an idiomatic method like any. A red flag is manually looping.

What are the primary advantages of using a data class?
Android & Kotlin2 min read

What are the primary advantages of using a data class?

Tests Kotlin boilerplate reduction and value semantics. Name three generated functions like equals, hashCode, and copy; explain structural equality; and show copy updating immutable UI state.

What are the advantages of a Kotlin data class?
Android & Kotlin2 min read

What are the advantages of a Kotlin data class?

Tests knowledge of Kotlin's boilerplate reduction for data holders. A good answer defines the advantage (conciseness), names generated functions like equals, hashCode, and copy, and explains copy for immutable state updates.

What are the advantages of a Kotlin data class and its functions?
Android & Kotlin2 min read

What are the advantages of a Kotlin data class and its functions?

Tests knowledge of Kotlin's idiomatic features. A good answer explains the main advantage (boilerplate reduction), lists generated functions like toString() and equals(), and describes copy() for immutable state updates.

Explain lateinit var versus val by lazy in Android
Android & Kotlin2 min read

Explain lateinit var versus val by lazy in Android

Tests deferred initialization and lifecycle coupling. Great answers contrast lateinit var's imperative assignment with lazy's first-access delegation, mapping lateinit to injected Activity fields and lazy to expensive computed objects.

lateinit var vs. val by lazy in Android
Android & Kotlin2 min read

lateinit var vs. val by lazy in Android

Tests your grasp of Kotlin's non-nullable property initialization. Define lateinit (mutable, framework-init) vs. lazy (immutable, deferred-init). Use lateinit for Views in onCreate and lazy for expensive objects. Red flag: confusing their mutability.

lateinit var vs. val by lazy in Android
Android & Kotlin2 min read

lateinit var vs. val by lazy in Android

Tests your grasp of Kotlin property initialization and its lifecycle implications. A good answer contrasts mutability (var/val), initialization timing, and thread safety.

Explain higher-order functions and implement filterAndTransform
Android & Kotlin2 min read

Explain higher-order functions and implement filterAndTransform

Tests whether you can define higher-order functions and use lambdas idiomatically in Kotlin. A strong answer defines HOFs as functions that take or return functions, then implements filterAndTransform with filter and map.

Explain and implement a higher-order function in Kotlin
Android & Kotlin2 min read

Explain and implement a higher-order function in Kotlin

Tests your grasp of functions as first-class citizens. Define a higher-order function, explain it takes/returns functions, then implement filterAndTransform using the specified lambdas.

Explain and implement a Kotlin higher-order function
Android & Kotlin2 min read

Explain and implement a Kotlin higher-order function

Tests understanding of first-class functions and lambda usage. First, define a higher-order function (HOF) as one that takes/returns functions. Then, implement the requested function, iterating to apply the predicate and transform.

When would you use a sealed class instead of an enum?
Android & Kotlin2 min read

When would you use a sealed class instead of an enum?

This tests closed hierarchies versus singleton constants. A strong answer contrasts enums with sealed class instances, shows a NetworkResult example with data-bearing branches, and highlights exhaustiveness.

When would you use a sealed class instead of an enum?
Android & Kotlin2 min read

When would you use a sealed class instead of an enum?

This tests your understanding of state representation. Explain that sealed classes define a hierarchy of types that can hold different data, while enums are a set of singleton constants.