-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDslMarker.kt
More file actions
59 lines (42 loc) · 1.02 KB
/
DslMarker.kt
File metadata and controls
59 lines (42 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package concepts_playground
import kotlin.properties.Delegates
@DslMarker
annotation class SuperMobile
interface Device
open class Mobile: Device {
fun ring() {
println("ring ring")
}
}
@SuperMobile
class Android : Mobile() {
fun multiTask() {
println("I can multi-task")
}
}
fun buildMobile(builder: Mobile.() -> Unit): Mobile {
return Mobile().apply(builder)
}
fun buildAndroid(builder: Android.() -> Unit): Mobile {
return Android().apply(builder)
}
fun main() {
buildAndroid {
ring()
multiTask()
}
}
class Newsletter {
val newestArticleObservers = mutableListOf<(String) -> Unit>()
var newestArticleUrl: String by Delegates.observable("") { _, _, newValue ->
newestArticleObservers.forEach {
it(newValue)
}
}
fun observe() {
val newsletter = Newsletter()
newsletter.newestArticleObservers.add { newestArticleUrl ->
println("New Baeldung article: ${newestArticleUrl}")
}
}
}