Last active
May 26, 2020 08:55
-
-
Save msymt/9ce663e0fcf9058c9a6d2290fdc5c6b5 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
val String.lastChar: Char | |
get() = get(length - 1) | |
var StringBuilder.lastChar: Char | |
get() = get(length - 1) | |
set(value: Char) { | |
this.setCharAt(length - 1, value) | |
} | |
/* | |
>>>println("Kotlin!".lastChar) | |
! | |
>>>val sb = StringBuilder("Kotlin?") | |
>>>println(sb) | |
Kotlin? | |
>>>sb.lastChar = '!' | |
>>>println(sb) | |
Kotlin! | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment