FileDocCategorySizeDatePackage
ClassInfoDemo.javaAPI DocExample3154Sun Dec 14 22:47:40 GMT 2003oreilly.hcj.reflection

ClassInfoDemo

public class ClassInfoDemo extends Object
Demonstrates usage of various class information methods.
author
Robert Simmons jr. (kraythe)
version
$Revision: 1.3 $

Fields Summary
Constructors Summary
Methods Summary
public static voidmain(java.lang.String[] args)
Demonstration Method

param
args Demonstration Method.

		final Set classes = new HashSet();
		classes.add(Class.class);
		classes.add(Comparable.class);
		classes.add(Serializable.class);
		classes.add(Integer.class);
		classes.add(int.class);
		classes.add(Float[].class);
		classes.add(String.class);
		classes.add(double[].class);
		classes.add(boolean.class);

		// --
		System.out.println("Finding interface Class objects in the set.");
		Iterator iter = classes.iterator();
		while (iter.hasNext()) {
			useIsInterface((Class)iter.next());
		}

		System.out.println("\nFinding primitive Class objects in the set.");
		iter = classes.iterator();
		while (iter.hasNext()) {
			useIsPrimitive((Class)iter.next());
		}

		System.out.println("\nFinding array Class objects in the set.");
		iter = classes.iterator();
		while (iter.hasNext()) {
			useIsArray((Class)iter.next());
		}
	
public static voiduseIsArray(java.lang.Class dataType)
Demonstrates usage of isArray from Class.

param
dataType The data type to check.
throws
NullPointerException If the user passes null for dataType.

		if (dataType == null) {
			throw new NullPointerException();
		}
		if (dataType.isArray()) {
			System.out.print(dataType.getName());
			System.out.println("\t ==> " + dataType.getComponentType());
		}
	
public static voiduseIsInterface(java.lang.Class dataType)
Demonstrates usage of isInterface from Class.

param
dataType The data type to check.
throws
NullPointerException If the user passes null for dataType.

		if (dataType == null) {
			throw new NullPointerException();
		}
		if (dataType.isInterface()) {
			System.out.println(dataType.getName());
		}
	
public static voiduseIsPrimitive(java.lang.Class dataType)
Demonstrates usage of isPrimitive from Class.

param
dataType The data type to check.
throws
NullPointerException If the user passes null for dataType.

		if (dataType == null) {
			throw new NullPointerException();
		}
		if (dataType.isPrimitive()) {
			System.out.println(dataType.getName());
		}