# The if-inherits statement enables you to use the object in the block statements # according to the "inherits" type. If you have control over all code, it would be # better to create a method in a common base class or interface, but sometimes the # classes in question are not under your control, so... class One get foo as int return 1 class Two get bar as int return 2 class Test shared def main Test().run def run .testReferenceType .testPrimitiveType def testReferenceType .check(One(), 1) .check(Two(), 2) def check(obj as Object, value as int) if obj inherits One assert obj.foo==value # using a One member with no casting else if obj inherits Two assert obj.bar==value # using a Two member with no casting else throw Exception('fall through') def testPrimitiveType x as Object = 5 flag as bool = false if x inherits int .processInt(x) flag = true CobraCore.noOp(flag) def processInt(i as int) pass