Skip to content

Instantly share code, notes, and snippets.

@JayBazuzi
Created July 4, 2022 00:10
Show Gist options
  • Save JayBazuzi/ca1429ea1d5b7a76de64d7cb7108bc73 to your computer and use it in GitHub Desktop.
Save JayBazuzi/ca1429ea1d5b7a76de64d7cb7108bc73 to your computer and use it in GitHub Desktop.
Demonstration of asserting events in Kotlin
fun main() {
val foo = Foo()
val aClass = AClass()
aClass.OnBaz = foo::Bar
aClass.Do()
println(aClass.OnBaz == aClass.OnBaz)
println(aClass.OnBaz)
}
class Foo {
fun Bar(message: String) {
println(message)
}
}
class AClass {
var OnBaz: (message: String) -> Unit = { }
fun Do() {
OnBaz("Hello, World!")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment