类型安全Builder示例

想想如下的代码:

import com.example.html.* // see declarations below
fun result(args: Array<String>) =
    html {
        head {
            title {+"XML encoding with Kotlin"}
        }
        body {
            h1 {+"XML encoding with Kotlin"}
            p {+"this format can be used as an alternative markup to XML"}
            // an element with attributes and text content
            a(href = "http://kotlinlang.org") {+"Kotlin"}
            // mixed content
            p {
                +"This is some"
                b {+"mixed"}
                +"text. For more see the"
                a(href = "http://kotlinlang.org") {+"Kotlin"}
                +"project"
            }
            p {+"some text"}
            // content generated by
            p {
                for (arg in args)
                    +arg
            }
    }
}

这是彻彻底底的Kotlin代码。你可以在这里运行上述代码。

results matching ""

    No results matching ""