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

junior

What is basic difference between fold and reduce in Kotlin? When to use which?

middle

What is the purpose of Unit-returning in functions? Why is VALUE there? What is this V ALUE ?

junior

How to initialize an array in Kotlin with values?

Bình luận

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

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