Casts
From RemObjects Software
This is a Oxygene Language Feature topic
Feel free to add your notes to this topic below.
Type Casts
Typecasting allows you to override the type of a class to that of one of its descendants. There are two difference syntaxes available:
<variable> as <type> <type>(<variable>)
In the first, the type is checked first and an exception is raised if the variable is not the correct type.
In the second syntax, the cast will return nil if the type does not match.
Is
The "is" keyword is used in two contexts:
- type checking
- generic constraints
Type Checking
if <object> is <type> then ... if <object> is not <type> then ...
Generic Constraints
Within a generics context, 'is' is used within a where clause:
type MyArrayList<T> = public class(ArrayList, IPersistentCollection) where T is PersistentObject, T has constructor;
As well as allowing you to check for a particular type, Oxygene generics also supports 'is record' and 'is class':
type GenericThatOnlyTakesARecord<T> = class where T is record; FVal: T; public constructor (Val: T); end; GenericThatOnlyTakesAClass<T> = class where T is class; FVal: T; public constructor (Val: T); end;
See Also
Product: RemObjects Oxygene (formerly known as Chrome)
Current version: 3.0
Previous Versions: 'Joyride' (2.0), 'Floorshow' (1.5), 'Adrenochrome' (1.0)
Glossary — Keywords — Language Features — Platform Features — Samples — Articles — How To — Issues
Categories: Text | Oxygene | Language | Feature
