mirror of
https://github.com/jlengrand/kotlin.git
synced 2026-05-13 08:31:31 +00:00
21 lines
540 B
Kotlin
21 lines
540 B
Kotlin
class My(val value: Int)
|
|
|
|
inline fun <T, R> T.performWithFinally(job: (T)-> R, finally: (T) -> R) : R {
|
|
try {
|
|
return job(this)
|
|
} finally {
|
|
return finally(this)
|
|
}
|
|
}
|
|
|
|
inline fun <T, R> T.performWithFailFinally(job: (T)-> R, failJob : (e: RuntimeException, T) -> R, finally: (T) -> R) : R {
|
|
try {
|
|
return job(this)
|
|
} catch (e: RuntimeException) {
|
|
return failJob(e, this)
|
|
} finally {
|
|
return finally(this)
|
|
}
|
|
}
|
|
|
|
inline fun String.toInt2() : Int = java.lang.Integer.parseInt(this) |