Java Reference
In-Depth Information
memory,andreturnsa Class objectthatrepresentstheclassorinterface. Listing4-10
demonstrates forName() and additional methods described in this table.
Listing 4-10. Using reflection to decompile a type
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
class Decompiler
{
public static void main(String[] args)
{
if (args.length != 1)
{
System.err.println("usage: java Decompiler class-
name");
return;
}
try
{
decompileClass(Class.forName(args[0]), 0);
}
catch (ClassNotFoundException cnfe)
{
System.err.println("could not locate "+args[0]);
}
}
static void decompileClass(Class<?> clazz, int in-
dentLevel)
{
indent(indentLevel*3);
Sys-
tem.out.print(Modifier.toString(clazz.getModifiers())+"
");
if (clazz.isEnum())
Search WWH ::




Custom Search