Created
November 23, 2016 15:00
-
-
Save sliskiCode/55b1a7ca61124a14dfea5f3a6fa78698 to your computer and use it in GitHub Desktop.
7 things you probably don’t know about Kotlin #7
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; | |
| Nullcheck.ifNull(name, new Function1<Object, Unit>() { | |
| @Override | |
| public Unit invoke(Object o) { | |
| return null; | |
| } | |
| }); | |
| } | |
| // Any.kt | |
| @file:JvmName("Nullcheck") | |
| package ... | |
| 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