


Since non Nullable reference variables can never be null. Str2 = null // this would not result in compilation error For example, Nullable string can be declared by using Nullable string, written as String? var str2: String? = "Kotlin Tutorial Blog"

To make a reference as null, kotlin has separate reference type for each of the type known as Nullable type. Now, let’s have look at Nullable type system: Kotlin Nullable Type Reference The above part of the code gives compilation error as Kotlin does not allows Non Nullable reference types to be null. It would give an error as below: var str: String = "hello" Let’s take an example of variable of type String ‘str’, if we try to assign it value as null. The default type of reference which assumes or forces that variable or reference cannot be null. Let’s understand their working in detail as below: Kotlin Non Nullable Type Reference Nullable Type System (holding Nullable references) and Non – Nullable Type System (holding non Nullable references). Kotlin language has two distinct types of type system that can be used to hold references for either type i.e. Let’s have look at Kotlin type systems in detail. To solve the issue above, kotlin has a separate type system for it.

Data Inconsistency: This could occur due to one of the reasons:.Throw Keyword: When the developer explicitly calls ‘throw NullPointerException()’.NPE can arise due one of the reasons or issues arising in our code. Causes for Arising of Null Pointer Exception Since this type system is not available in Java, developer needs to handle the case for every null value explicitly. Flutter Null Safety with example - dart migrate - flutter tutorial
