Alexander Suraphel
08/24/2021, 4:34 PM*val* x: String? = y *as* String? and
*val* x: String? = y *as*? String ?Richard Gomez
08/24/2021, 4:34 PMas, if y cannot be safely cast to String it will throw an exception. With as?, it will simply return null.CLOVIS
08/24/2021, 4:53 PMString?
as String?
Crashes for everything that isn't a String or null,
as? String
Accepts any value, returns a String if it is one, null otherwise.CLOVIS
08/24/2021, 4:53 PMnull)CLOVIS
08/24/2021, 4:54 PMnull, the solution is to use as String, which will crash for any non-String value (even null)Alexander Suraphel
08/24/2021, 4:57 PM