Skip to content

Commit

Permalink
Merge pull request Kotlin#77 from nastra/ext-function-improved-docs
Browse files Browse the repository at this point in the history
Improve docs in ExtensionFunctions examples
  • Loading branch information
svtk authored May 26, 2017
2 parents c4f9a43 + 80b0bb8 commit 1203997
Showing 1 changed file with 4 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ package i_introduction._9_Extension_Functions
import util.TODO
import util.doc9

// declares an extension function that returns the last character
fun String.lastChar() = this.get(this.length - 1)

// 'this' can be omitted

// declares an extension function where 'this' can be omitted
fun String.lastChar1() = get(length - 1)

fun use() {
fun useExtensionFunction() {
// try Ctrl+Space "default completion" after the dot: lastChar() is visible
"abc".lastChar()
}
Expand Down

0 comments on commit 1203997

Please sign in to comment.