Null safety nghĩa là các biến không thể chứa null trừ khi được đánh dấu nullable bằng ?.
- Điều này giúp phòng ngừa lỗi
NullPointerExceptionở runtime bằng cách phát hiện lỗi ngay lúc compile. - Với null safety, lập trình viên phải có chủ đích rõ ràng về biến nào có thể null, giúp code an toàn hơn và trình biên dịch tối ưu hiệu quả hơn.
Null safety means variables cannot contain null unless explicitly marked as nullable with ?.
- This prevents
NullPointerExceptionerrors at runtime by catching them at compile time instead. - With null safety, you must be intentional about which variables can be null, making code safer and allowing compiler optimizations.