Câu hỏi phỏng vấn Kotlin
Câu hỏi

What are scope functions in Kotlin?

Câu trả lời

Scope functions in Kotlin are a set of functions that allow you to execute a block of code within the context of an object. They provide a concise way to perform operations on an object without repeating its name. There are five main scope functions in Kotlin:

  1. let: Executes a block of code on a non-null object and returns the lambda result. It is commonly used for safe execution with nullable objects and chaining multiple operations[1][3][4].

  2. run: Executes a block of code on an object and returns the lambda result. It can be used to operate on nullable objects and compute the result[1][3].

  3. with: Executes a block of code on an object and returns the lambda result. It is called without the context object and is useful for grouping function calls on an object[1][3][4].

  4. apply: Executes a block of code on an object and returns the context object. It is commonly used fo...

middle

middle

Gợi ý câu hỏi phỏng vấn

middle

What is lateinit in Kotlin and when would you use it?

middle

What is a difference between a class and object in Kotlin?

junior

What is the difference between var and val in Kotlin?

Bình luận

Chưa có bình luận nào

Chưa có bình luận nào