Last active
June 30, 2016 17:20
-
-
Save kikuchy/fc87d015be859196ee9ef53525df9dd4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class IntentDelegateExt { | |
operator fun getValue(thisRef: Activity, property: KProperty<*>): String? = | |
thisRef.intent.getStringExtra(property.name) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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