Skip to content

Instantly share code, notes, and snippets.

@MarcinusX
Created October 2, 2019 19:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MarcinusX/f12bf68a724d4e566f2c9aeaf4ba1978 to your computer and use it in GitHub Desktop.
Save MarcinusX/f12bf68a724d4e566f2c9aeaf4ba1978 to your computer and use it in GitHub Desktop.
// Niech x będzie nullem
int x;
// Operator ?? umożliwia użycie pewnej wartości w przypadku wystąpienia nulla
print(x ?? 7) //printuje 7
// Dodatkowo możemy odwoływać się do zmiennych i metod za pomocą operatora ?. aby uninkąć NullPointerów
print(x?.toString()); //printuje null
// Lub dowolnie to łączyć
print(x?.toString() ?? 'x był nullem'); //printuje 'x był nullem'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment