Dan Tech Academy

Câu Hỏi Phỏng Vấn Kotlin

Kotlin là ngôn ngữ bắt buộc cho Android developer 2026. Các câu hỏi phỏng vấn Kotlin tập trung vào null safety, coroutines, và tính năng đặc trưng so với Java. Dưới đây là 12 câu hỏi thường gặp nhất.

12 câu hỏi4 dễ / 5 trung bình / 3 khó

Danh Sách Câu Hỏi

Dễ Trung bình Khó
1
Null safety trong Kotlin hoạt động thế nào?dễ
Kotlin phân biệt nullable (String?) và non-null (String) ở compile time. Operators: ?. (safe call), ?: (elvis), !! (force unwrap - tránh dùng). let, also cho null checks. Smart cast sau null check. Giảm NullPointerException 70%+ so với Java.
2
Giải thích sự khác nhau giữa val, var, và const val?dễ
val: read-only reference (không thay đổi reference nhưng object bên trong có thể thay đổi). var: mutable reference. const val: compile-time constant, chỉ cho primitive và String, phải ở top-level hoặc companion object.
3
Data class là gì? Khác gì class thường?dễ
Data class tự generate equals(), hashCode(), toString(), copy(), componentN(). Yêu cầu: ít nhất 1 primary constructor parameter. Dùng cho DTO, model. Lưu ý: chỉ properties trong primary constructor tham gia generated functions.
4
Sealed class và enum class khác nhau thế nào?trung bình
Enum: fixed instances, mỗi instance giống nhau. Sealed class: restricted hierarchy, mỗi subclass có thể có state khác nhau. Sealed class phù hợp cho UI states (Loading, Success(data), Error(message)). when expression exhaustive check.
5
Extension functions hoạt động thế nào bên dưới?trung bình
Compile thành static function với receiver là tham số đầu tiên. Không thể access private members. Resolved statically (không polymorphic). Ví dụ: fun String.isEmail() compile thành static fun isEmail(String). Dùng cho utility functions.
6
Giải thích scope functions: let, run, with, apply, also?trung bình
let: it reference, return lambda result - dùng cho null check + transform. apply: this reference, return object - dùng cho object configuration. also: it reference, return object - dùng cho side effects. run: this reference, return lambda result. with: non-extension version của run.
7
Coroutine scope và structured concurrency là gì?khó
Scope quản lý lifecycle của coroutines. Structured concurrency: child coroutines cancel khi parent cancel. viewModelScope tự cancel khi ViewModel cleared. supervisorScope: child failure không cancel siblings. Luôn dùng structured concurrency, tránh GlobalScope.
8
suspend function là gì? Khác gì function thường?trung bình
suspend function có thể pause và resume mà không block thread. Chỉ gọi từ coroutine hoặc suspend function khác. Compiler transform thành state machine với Continuation. withContext(Dispatchers.IO) cho I/O operations.
9
Flow trong Kotlin là gì? Cold stream vs Hot stream?khó
Flow: asynchronous data stream. Cold (Flow): emit khi có collector, mỗi collector nhận stream riêng. Hot (StateFlow, SharedFlow): emit bất kể có collector hay không, share giữa collectors. StateFlow giữ latest value, SharedFlow configurable replay.
10
Inline functions và reified type parameters dùng khi nào?khó
inline: lambda body được copy vào call site, tránh object allocation. crossinline: lambda không được return. noinline: lambda không inline. reified: giữ type information tại runtime (bình thường bị type erasure). Dùng cho startActivity<T>(), Gson parsing.
11
Delegation trong Kotlin (by keyword) hoạt động thế nào?trung bình
Property delegation: by lazy (lazy init), by Delegates.observable (observe changes), by map (từ map). Class delegation: implement interface by delegating to another object. Giảm boilerplate, thay thế inheritance bằng composition.
12
Higher-order functions và lambdas trong Kotlin?dễ
Higher-order function nhận hoặc trả về function. Lambda: anonymous function { params -> body }. Trailing lambda syntax khi lambda là tham số cuối. Function type: (Int, Int) -> Int. Lambda capture variables từ outer scope (closure).

Câu Hỏi Thường Gặp

Junior: null safety, data class, extension functions, basic coroutines. Mid: sealed class, scope functions, Flow, structured concurrency. Senior: inline/reified, delegation, compiler behavior, performance implications.

Hiểu Java giúp trả lời câu hỏi so sánh (Kotlin compile thành gì trong bytecode). Nhưng nhiều công ty chỉ hỏi Kotlin thuần, đặc biệt cho dự án mới.

Chuẩn bị phỏng vấn tốt hơn với bài tập thực hành

Xem Mobile Action Pro

Hoặc xem Lộ Trình Android Developer 2026