Skip to content

Instantly share code, notes, and snippets.

@sliskiCode
Last active November 23, 2016 14:39
Show Gist options
  • Save sliskiCode/3b6d8a8b5d561b9c208eafd282573c6c to your computer and use it in GitHub Desktop.
Save sliskiCode/3b6d8a8b5d561b9c208eafd282573c6c to your computer and use it in GitHub Desktop.
7 things you probably don’t know about Kotlin #6
// 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