Last active
November 23, 2016 14:39
-
-
Save sliskiCode/3b6d8a8b5d561b9c208eafd282573c6c to your computer and use it in GitHub Desktop.
7 things you probably don’t know about Kotlin #6
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
| // Main.java | |
| public static void main(String[] args) { | |
| String name = null; | |
| AnyKt.ifNull(name, new Function1<Object, Unit>() { | |
| @Override | |
| public Unit invoke(Object o) { | |
| return null; | |
| } | |
| }); | |
| } | |
| // Any.kt | |
| inline fun <T> T?.ifNull(function: (T?) -> Unit) { | |
| if (this == null) function(this) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment