publicclass java.util.Date
{
public java.util.Date(java.lang.String);
public java.util.Date(int, int, int, int, int, int);
public java.util.Date(int, int, int, int, int);
public java.util.Date();
public java.util.Date(long);
public java.util.Date(int, int, int);
public boolean equals(java.lang.Object);
public java.lang.String toString();
public int hashCode();
public java.lang.Object clone();
public volatile int compareTo(java.lang.Object);
public int compareTo(java.util.Date);
public static java.util.Date from(java.time.Instant);
private void readObject(java.io.ObjectInputStream);
private void writeObject(java.io.ObjectOutputStream);
private final sun.util.calendar.BaseCalendar$Date normalize(sun.util.calendar.BaseCalendar$Date);
private final sun.util.calendar.BaseCalendar$Date normalize();
public boolean before(java.util.Date);
public boolean after(java.util.Date);
public static long parse(java.lang.String);
public int getSeconds();
public java.time.Instant toInstant();
public static long UTC(int, int, int, int, int, int);
public int getYear();
public long getTime();
public void setTime(long);
static final long getMillisOf(java.util.Date);
public void setDate(int);
public int getMonth();
private final sun.util.calendar.BaseCalendar$Date getCalendarDate();
public void setHours(int);
public int getHours();
public int getMinutes();
public void setMonth(int);
public void setMinutes(int);
public void setSeconds(int);
public void setYear(int);
private static final sun.util.calendar.BaseCalendar getCalendarSystem(long);
private static final sun.util.calendar.BaseCalendar getCalendarSystem(int);
private static final sun.util.calendar.BaseCalendar getCalendarSystem(sun.util.calendar.BaseCalendar$Date);
private final long getTimeImpl();
private static final java.lang.StringBuilder convertToAbbr(java.lang.StringBuilder, java.lang.String);
private static final synchronized sun.util.calendar.BaseCalendar getJulianCalendar();
public int getDate();
public int getDay();
public java.lang.String toLocaleString();
public java.lang.String toGMTString();
public int getTimezoneOffset();
public java.util.Date(java.lang.String);
public java.util.Date(int, int, int, int, int, int);
public java.util.Date(int, int, int, int, int);
public java.util.Date();
public java.util.Date(long);
public java.util.Date(int, int, int);
}
Process finished with exit code 0
代码
package reflection;
import java.util.*;
import java.lang.reflect.*;
public class ReflectionTest {
public static void main(String[] args) {
// read class name from command line args or user input
String name;
if(args.length > 0) name = args[0];
else
{
Scanner in = new Scanner(System.in);
System.out.println("输入一个类的名称 (例如 java.util.Date): ");
name = in.next();
}
try {
// Print class name and superclass name (if != Object)
Class cl = Class.forName(name);
Class supercl = cl.getSuperclass();
String modifiers = Modifier.toString(cl.getModifiers());
if(modifiers.length() > 0) System.out.print(modifiers + "");
System.out.print("class " + name);
if(supercl != null && supercl != Object.class) System.out.printf(" extends " + supercl.getName());
System.out.printf("\n{\n");
printConstructors(cl);
System.out.println();
printMethods(cl);
System.out.println();
printFields(cl);
System.out.println("}");
}
catch (ClassNotFoundException e)
{
e.printStackTrace();
}
System.exit(0);
}
/**
* Prints all constructors of a class
* @param cl a class
*/
private static void printFields(Class cl) {
Constructor[] constructors = cl.getDeclaredConstructors();
for (Constructor c : constructors)
{
String name = c.getName();
System.out.printf(" ");
String modifiers = Modifier.toString(c.getModifiers());
if(modifiers.length() > 0) System.out.printf(modifiers + " ");
System.out.printf(name + "(");
// print parameter types
Class[] paramTypes = c.getParameterTypes();
for (int j = 0; j < paramTypes.length; j++)
{
if(j > 0) System.out.printf(", ");
System.out.printf(paramTypes[j].getName());
}
System.out.println(");");
}
}
/**
* Prints all methods of a class
* @param cl a class
*/
public static void printMethods(Class cl)
{
Method[] methods = cl.getDeclaredMethods();
for (Method m : methods)
{
Class retType = m.getReturnType();
String name = m.getName();
System.out.print(" ");
// print modifiers, return type and method name
String modifiers = Modifier.toString(m.getModifiers());
if (modifiers.length() > 0) System.out.print(modifiers + " ");
System.out.print(retType.getName() + " " + name + "(");
// print parameter types
Class[] paramTypes = m.getParameterTypes();
for (int j = 0; j < paramTypes.length; j++)
{
if (j > 0) System.out.print(", ");
System.out.print(paramTypes[j].getName());
}
System.out.println(");");
}
}
/**
* Prints all constructors of a class
* @param cl a class
*/
public static void printConstructors(Class cl)
{
Constructor[] constructors = cl.getDeclaredConstructors();
for (Constructor c : constructors)
{
String name = c.getName();
System.out.print(" ");
String modifiers = Modifier.toString(c.getModifiers());
if (modifiers.length() > 0) System.out.print(modifiers + " ");
System.out.print(name + "(");
// print parameter types
Class[] paramTypes = c.getParameterTypes();
for (int j = 0; j < paramTypes.length; j++)
{
if (j > 0) System.out.print(", ");
System.out.print(paramTypes[j].getName());
}
System.out.println(");");
}
}
}