Nevertheless, the compiler and IDE need to display them sometimes (for example, in error messages or parameter info), so there is a mnemonic notation for them: Notation for platform typesĪs mentioned above, platform types can't be mentioned explicitly in the program, so there's no syntax for them in the language. Overall, the compiler does its best to prevent nulls from propagating far through the program although sometimes this is impossible to eliminate entirely, because of generics. Assertions are also emitted when you pass platform values to Kotlin functions expecting non-null values and in other cases. This prevents Kotlin's non-null variables from holding nulls. If you choose a non-null type, the compiler will emit an assertion upon assignment. Val notNull: String = item // allowed, may fail at runtime Val nullable: String? = item // allowed, always works
0 Comments
Leave a Reply. |