Last active
May 30, 2018 03:48
-
-
Save pambrose/1a006db13ae299ff2ff059686d7c4917 to your computer and use it in GitHub Desktop.
Nullability in Kotlin Generic Extension Function Receivers
This file contains hidden or 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
| fun main(args: Array<String>) { | |
| val nonnNullStr = "Str-" | |
| val nullStr: String? = null | |
| println(nonnNullStr.nullableConcat("1")) | |
| println(nullStr.nullableConcat("2")) | |
| println(nonnNullStr.nonnullableConcat("3")) | |
| // Why is this legal? | |
| println(nullStr.nonnullableConcat("4")) | |
| } | |
| fun <T> T?.nullableConcat(b: T) = this.toString() + b.toString() | |
| fun <T> T.nonnullableConcat(b: T) = this.toString() + b.toString() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment