Cast operator

To cast a variable to another type, you have to use the cast operator (as):

var fullname: String = name as String

The cast operator will throw an error if the variable you're trying to cast is not of the type you're trying to cast it to. To prevent this, you can make use of the safe cast operator (as?):

var gen: String? = gender as? String

The safe cast operator does not throw an error but returns a null if the cast is not possible.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset