Skip to content

Casting

Casting types is a fundamental part of statically typed programming languages.

Upcasting

class Base {}

class Super extends Base {}

var x: Base = Super();

print(type(x)); // Base (not Super!)

Downcasting

class Base {}

class Super extends Base {}

var x: Base = Super();

var y = (Super) x;

print(type(y)); // Super