Sobes.tech
Junior

What are double exclamation marks used for?

sobes.tech AI

Answer from AI

They are used to convert a nullable type to a non-nullable type, throwing a NullPointerException if the value is null. This is called the "not null assert operator".

// Declare a nullable string
var nullableString: String? = "Hello"

// Use the not null assert operator
val nonNullableString: String = nullableString!!

// If nullableString were null, an NPE would be thrown here