A type cast instructs the compiler that an expression has a specific type.
Warning️️: Type casts are by nature dangerous and should be used with caution!
A Flix programmer should not normally use type casts except in two cases:
- To cast a Java type to one of its super-types.
- To cast the
nullvalue to a nullable type.
Both use cases are legitimate and safe.
The expression below casts a
String to an
"Hello World" as ##java.lang.Object
The expression below casts the
null value (of type
null as ##java.lang.String
The expression below contains an illegal cast and triggers a
(123, 456) as String
Note: A type cast should not be used to box or unbox primitive values. Instead use the designated Java methods. For example,