Skip to content

Instantly share code, notes, and snippets.

@breandan
Created March 31, 2019 16:40
Show Gist options
  • Save breandan/8aecbca59419577981061617ed97dd03 to your computer and use it in GitHub Desktop.
Save breandan/8aecbca59419577981061617ed97dd03 to your computer and use it in GitHub Desktop.
Lazy properties, nullary functions, and custom getters oh my
object C {
inline fun longOp(): String {
val ms = System.currentTimeMillis()
while (true) if (System.currentTimeMillis() - ms > 30000) break
return "abc"
}
// val zoo = longOp()
val quick = "hello"
fun foo() = longOp()
val bar: () -> String
get() = { longOp() }
val baz = { longOp() }
val bat by lazy { longOp() }
// fun qux() = object { val longOp = C.longOp() }
}
println(C.baz)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment