Type Casting in Scala

In the following lesson, you will be introduced to type casting and learn how to change the data type of a variable.

We'll cover the following

Introduction

Sometimes we find ourselves in a situation where we need the value of an already existing variable in a different data type than the one with which it was defined. This is where type casting comes in. Type casting is an approach which allows changing the data type of a variable or an expression from one to another.

One thing to remember is that not every data type can be converted to a data type of choice. Let’s look at the type casting flow in Scala to better understand which data type can be converted to which data type.

Create a free account to access the full course.

By signing up, you agree to Educative's Terms of Service and Privacy Policy