What is the difference between
x as? String
and
x as String?
They both seem to produce a String?
String?
The difference lies in when x is a different type:
x
val x: Int = 1 x as String? // Causes ClassCastException, cannot assign Int to String? x as? String // Returns null, since x is not a String type.