Skip to content

Commit

Permalink
Update some feature examples
Browse files Browse the repository at this point in the history
(cherry picked from commit 1dca14a)
  • Loading branch information
yole committed May 11, 2017
1 parent 924bb03 commit f4ee66c
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 9 deletions.
2 changes: 1 addition & 1 deletion kotlin-features/concise.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ data class Customer(val name: String, val email: String, val company: String)
Or filter a list using a lambda expression:

``` kotlin
val positiveNumbers = list.filter {it > 0}
val positiveNumbers = list.filter { it > 0 }
```

Want a singleton? Create an object:
Expand Down
2 changes: 1 addition & 1 deletion kotlin-features/kotlin-features.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
content_file: versatile.html

- title: Interoperable
description: Leverage existing frameworks and libraries of the JVM with 100% Java Interoperability.
description: Leverage existing libraries for JVM, Android and the browser with full interoperability.
content_file: interoperable.md

- title: Tooling
Expand Down
13 changes: 6 additions & 7 deletions kotlin-features/safe.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,22 @@
Get rid of those pesky NullPointerExceptions, you know, The Billion Dollar Mistake

``` kotlin
var output : String
output = null
var output: String
output = null // Compilation error
```

And of course, Kotlin protects you from mistakenly operating on nullable types,
including those from Java
Kotlin protects you from mistakenly operating on nullable types

``` kotlin
println(output.length())
val data: String? = null // Nullable type
println(data.length()) // Compilation error
```

And if you check a type is right, the compiler will auto-cast it for you

``` kotlin
fun calculateTotal(obj: Any) {
if (obj is Invoice) {
if (obj is Invoice)
obj.calculateTotal()
}
}
```

0 comments on commit f4ee66c

Please sign in to comment.