Last active
April 20, 2021 08:43
-
-
Save davidmigloz/0e145196de3de528261c4bff6007cc7e to your computer and use it in GitHub Desktop.
Dart vs Kotlin: nullability operators
This file contains 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
void main() { | |
int? nullableNumber = 1; | |
int number = nullableNumber!; | |
List<int>? myList; // null | |
print(myList?.length ?? 0); // 0 | |
myList ??= [1, 2, 3]; | |
print(myList.length); // 3 | |
} |
This file contains 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
fun main() { | |
val nullableNumber: Int? = 1 | |
val number = nullableNumber!! | |
var myList: List<Int>? = null | |
println(myList?.size ?: 0) // 0 | |
myList = myList ?: listOf(1, 2, 3) | |
println(myList.size) // 3 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment