FileDocCategorySizeDatePackage
ObtainingClassInstances.javaAPI DocExample2080Sun Dec 14 22:47:32 GMT 2003oreilly.hcj.reflection

ObtainingClassInstances

public class ObtainingClassInstances extends Object
Demonstration of how to obtain instances of java.lang.Class.
author
Robert Simmons jr. (kraythe)
version
$Revision: 1.3 $

Fields Summary
protected static Integer
someInteger
An Integer object
protected static Object
someObject
A generic object.
protected static String
someString
A String.
protected static int
someInt
An int.
protected static int[]
intArray
An array of ints.
Constructors Summary
Methods Summary
public static voidmain(java.lang.String[] args)
Main method.

param
args Command line arguments.


	        	 
	      
		// -- Print out the Class instances. 
		System.out.println(someInteger.getClass());
		System.out.println(someString.getClass());
		System.out.println(intArray.getClass());
		System.out.println(Object.class);
		System.out.println(Integer.class);
		System.out.println(int.class);
		System.out.println(String.class);
		System.out.println(Comparable.class);
		System.out.println(Object[].class);

		// -- Things that WON'T work
		// System.out.println(someObject.getClass());  // <= Exception 
		// System.out.println(someInt.getClass()); // <= Compiler errror
	
public voidwriteClass(java.lang.Object obj)
Demonstration of a method that doesnt check for null.

param
obj The object passed.

		System.out.println(obj.getClass());