“Lambda with receiver”: what is this Kotlin design?

I am considering this Kotlin object declaration:

object A : B({ variableName1 = "text1" variableName2 = "text2" params { param("Foo", "Bar") } }) 

And I can’t understand what the argument is for the constructor of class B.

In this example, I deliberately distracted the information, but class B actually

 jetbrains.buildServer.configs.kotlin.v10.BuildType 

And I can not find the documentation for this type. I found something that was close , but this is a definition for an interface and therefore does not have a constructor.

To summarize, what is this design in Kotlin?

 { variableName1 = "text1" variableName2 = "text2" params { param("Foo", "Bar") } } 
+5
source share
1 answer

This design is called the “Lambda with Receiver,” the so-called “Functional Letters with Receiver,” which you will find in the Kotlin DSL implementations. For example, see the DSL HTML Builder .

I have described in detail the whole concept in this thread.

+8
source

Source: https://habr.com/ru/post/1272549/


All Articles