FileDocCategorySizeDatePackage
RTTIDemo.javaAPI DocExample2184Sun Dec 14 22:47:30 GMT 2003oreilly.hcj.review

RTTIDemo

public class RTTIDemo extends Object
A demonstration of Run Time Type Identifictation, RTTI, in Java.
author
Robert Simmons jr. (kraythe)
version
$Revision: 1.5 $

Fields Summary
Constructors Summary
Methods Summary
public static final voidbasicRTTIDemo()
Demonstrates basic RTTI functionality.

		Float y = new Float(15.0);
		String name = "Fred";
		System.out.println(y.getClass());
		System.out.println(name.getClass());
	
public static final voidcastingWithRTTI()
Demonstrates how RTTI enforces type safety.

		A a = null;
		A a1 = new A();
		B b = new B();
		C c = new C();

		a = (A)b;  // no problem
		b = (B)a;  // still no problem, casting back to what it was created as. 
		a = a1;  // Same type so no problem
		Object d = (Object)c;  // no problem becasue of implicit inheritance
		c = (C)d;  // casting back
	
public static final voidmain(java.lang.String[] args)
Main demonstration method.

param
args Command line arguments.

		basicRTTIDemo();