The types of systems that support Kotlin majorly distinguishes among the references that can carry nullable references, and the ones cannot carry nullable references. Kotlin is a null safety language aimed to eliminate the null pointer exception or null reference from the code, which is deliberately known as A Billion Dollar Mistake.
The most conventional stumbling block of many programming languages is that while accessing a member of a null reference, it results to be a NullPointerException, which could be because of !! operator or this constructor used somewhere else and passed at another point of code. The nullable property requires confirmation for the null check every time prior to its utilization.
In Kotlin, the system distinguishes between null references and not null references.
For example, a String variable cannot hold null:
For Example 5:
fun main(args: Array<String>){
var x: String = "GURU99 is the only place where you will get maximum technical content!" // Not Null by default
println("x is : $x")
// You cannot assign null variable to not-nullable variables
// a=null // it will give compilation error
var y: String? = "Thanks for visiting GURU99"
// Nullable Variable
println("y is : $y")
y = null
println("y is : $y")
}
Output: