Kotlin Koans 39 Builders how it works

目次

Builders: how it works (Playground)

Description

Look at the questions below and give your answers

以下の問題を見て、回答してください。


1. In the Kotlin code

tr {
    td {
        text("Product")
    }
    td {
        text("Popularity")
    }
}

'td' is

a. special built-in syntactic construct (特別なビルトイン構文の構造)

b. function declaration (関数宣言)

c. function invocation (関数呼び出し)


2. In the Kotlin code

tr (color = "yellow") {
    td {
        text("Product")
    }
    td {
        text("Popularity")
    }
}

'color' is

a. new variable declaration (新しい変数の宣言)

b. argument name (引数の名前)

c. argument value (引数の値)


3. The block

{
    text("Product")
}

from the previous question is

a. block inside built-in syntax construction td (ビルトイン構文の構造内のブロック)

b. function literal (or "lambda") (関数リテラルもしくはラムダ)

c. something mysterious (不明)


4. For the code

tr (color = "yellow") {
    this.td {
        text("Product")
    }
    td {
        text("Popularity")
    }
}

which of the following is true

a. this code doesn't compile (このコードはコンパイルできない)

b. this refers to an instance of an outer class (this は外部クラスのインスタンスを参照する)

c. this refers to a receiver parameter TR of the function literal: (this は関数リテラルのレシーバーパラメータTRを参照する)

tr (color = "yellow") {
    this@tr.td {
        text("Product")
    }
}

Code

import Answer.*

enum class Answer { a, b, c }

val answers = mapOf<Int, Answer?>(
    1 to c,
    2 to b,
    3 to b,
    4 to c
)

← Posts