Skip to content

Instantly share code, notes, and snippets.

@kikuchy
Last active June 30, 2016 17:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kikuchy/fc87d015be859196ee9ef53525df9dd4 to your computer and use it in GitHub Desktop.
Save kikuchy/fc87d015be859196ee9ef53525df9dd4 to your computer and use it in GitHub Desktop.
class IntentDelegateExt {
operator fun getValue(thisRef: Activity, property: KProperty<*>): String? =
thisRef.intent.getStringExtra(property.name)
}
package demo
import java.util.*
import kotlin.properties.ReadOnlyProperty
import kotlin.reflect.KProperty
class OmikujiProperty{
private val random = Random()
operator fun getValue(thisRef: Any?, property: KProperty<*>): String {
return when(random.nextInt(4)) {
0 -> "大吉"
1 -> "中吉"
2 -> "小吉"
else -> "凶"
}
}
}
class Application {
val omikuji: String by OmikujiProperty()
}
fun main(args: Array<String>) {
val app = Application()
print(app.omikuji)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment