Type Manipulation
Get object type | Is instance of (includes subtypes) | Upcasting | Downcasting | ||
---|---|---|---|---|---|
Runtime check | No check | ||||
ABAP Objects | = | ?= | |||
C++ (STL) | typeid(x) | dynamic_cast<type *>(&x) != NULL | dynamic_cast<type*>(ptr) | (type*) ptr or static_cast<type*>(ptr) |
|
C# | x.GetType | x is type | (type) x or x as type | ||
D | typeid(x) | cast(type) x | |||
Delphi | x is type | x as type | |||
Java | x.getClass | x instanceof class | (type) x | ||
Objective-C (Cocoa) | ] | (type*) x | |||
JavaScript | x.constructor | x instanceof class | |||
Visual Basic .NET | x.GetType | TypeOf x Is type | CType(x, type) or TryCast(x, type) | ||
Eiffel | x.generating_type | attached {TYPE} x | attached {TYPE} x as down_x | ||
Python | type(x) | isinstance(x, type) | |||
PHP | get_class(x) | x instanceof class | |||
Perl | ref(x) | x->isa("class") | |||
Perl 6 | x.WHAT | x.isa(class) | type(x) or x.type |
||
Ruby | x.class | x.instance_of?(type) or x.kind_of?(type) |
|||
Smalltalk | x class | x isKindOf: class | |||
Windows PowerShell | x.GetType | x -is | x or x -as | ||
OCaml | (x :> type) | ||||
F# | x.GetType | x :? type | (x :?> type) |
Read more about this topic: Comparison Of Programming Languages (object-oriented Programming)
Famous quotes containing the words type and/or manipulation:
“I can barely conceive of a type of beauty in which there is no Melancholy.”
—Charles Baudelaire (18211867)
“The principle that human nature, in its psychological aspects, is nothing more than a product of history and given social relations removes all barriers to coercion and manipulation by the powerful.”
—Noam Chomsky (b. 1928)