sindrenm
03/02/2018, 12:50 PMas? String
and as String?
? simple smile)diesieben07
03/02/2018, 1:09 PMas? String
will try to cast to non-null String and give null
if not possible (i.e. value is null or something other than String, such as Int).
as String?
will cast to nullable String and fail if it's something else (e.g. Int).diesieben07
03/02/2018, 1:10 PMsindrenm
03/02/2018, 1:13 PMString?
(unless it fails because it's an Int
or whatever)?sindrenm
03/02/2018, 1:14 PM("Hello World" as? String).length
sindrenm
03/02/2018, 1:14 PMnull
first (i.e. ?.length
).sindrenm
03/02/2018, 1:16 PMsindrenm
03/02/2018, 1:16 PM(1337 as? String) // => null
sindrenm
03/02/2018, 1:22 PMdiesieben07
03/02/2018, 1:23 PM1337 as? String
is null, 1337 as String?
throws ClassCastException
sindrenm
03/02/2018, 1:27 PM