October 2019
Intermediate to advanced
434 pages
11h 54m
English
As we start to nest function calls, we may end up with multiple receiver contexts available to us. This can start to get confusing or even incorrect. For example, in the HTML example, creating a HEAD element inside another HEAD is probably not the desired behavior.
To help avoid this situation, we can make use of the DslMarker annotations. The use of these annotations can tell the Kotlin compiler when to limit the scope of a given function so that outer scopes are no longer available.
To create a DslMarker, we can create a custom annotation, as shown in the HTML DSL example:
@DslMarkerannotation class HtmlTagMarker
By adding that annotation to the parent class, Tag, we can indicate which receivers are available within a given ...
Read now
Unlock full access