Skip to content

Instantly share code, notes, and snippets.

@sliskiCode
Created November 23, 2016 15:00
Show Gist options
  • Select an option

  • Save sliskiCode/55b1a7ca61124a14dfea5f3a6fa78698 to your computer and use it in GitHub Desktop.

Select an option

Save sliskiCode/55b1a7ca61124a14dfea5f3a6fa78698 to your computer and use it in GitHub Desktop.
7 things you probably don’t know about Kotlin #7
// 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