Skip to content

Instantly share code, notes, and snippets.

@Laxystem
Last active November 10, 2024 17:27
Show Gist options
  • Save Laxystem/ddd5819c65498902116b496dd09bce98 to your computer and use it in GitHub Desktop.
Save Laxystem/ddd5819c65498902116b496dd09bce98 to your computer and use it in GitHub Desktop.
Nullability Java Kotlin
Not null Object! Any
Maybe-nullable Object Any!1
Nullable Object? Any?
Not null param T! T & Any
Nullable param T? T?
Operation Java Kotlin
Else original == null ? fallback : original original ?: fallback
Map if not null original == null ? null : map(original) original?.map()
Take if matches(original) ? original : null original.takeIf(::matches)
Take unless matches(original) ? null : original original.takeUnless(::matches)
Throw if null original (non-safe usage throws) original!!

Footnotes

  1. Cannot be declared.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment