Keyword for non-nullalble type inference #7695
-
When nullable reference types are enabled, you can declare objects using the I propose a new keyword -- |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 5 replies
-
The type of the variable isn't that important. The nullability state of the variable depends on the nullability of the expression used to initialize the variable and is tracked through flow analysis. The only time the nullability of the inferred variable type would even matter is if you reassigned it. There would be no warning on assigning a nullable value to the variable even if the previous value was non-nullable. However, flow analysis still takes place and an attempt at dereferencing the variable will issue a warning if you do not check for nullability. Importantly, nullable reference types never affects the behavior of the code. That is very intentional, so that you can switch NRTs on and off without any impact to the behavior of the code. Rather than |
Beta Was this translation helpful? Give feedback.
-
I honestly just think that the IDE and other tools should stop showing the variable type as nullable. That by itself would alleviate the majority of the confusion. |
Beta Was this translation helpful? Give feedback.
Kotlin's
val
syntax has nothing to do with nullability, it has to do with mutability. Kotlin uses the!!
postfix operator to forcibly unwrap a nullable value and throw at runtime.As mentioned, you can set those warnings to errors, and achieve this goal today with zero langu…