1.什么是类的声明:
(1)用什么修饰符修饰类:public,protect,private,abstract,static,final
(2)类的名称
(3)类的参数
(4)类继承自哪个类
(5) 类实现哪个接口
实现本文的小demo可以输出以下内容:
public class Main5
{
public static void main(String[] args) throws ClassNotFoundException
{
Class test=Class.forName("java.util.ArrayList");
//类的标准名称:java.util.ArrayList
System.out.println(test.getCanonicalName());
//也可以返回这个类的名称:java.util.ArrayList
System.out.println(test.getName());
//类的修饰符:public
System.out.println(Modifier.toString(test.getModifiers()));
//类实现的所有接口
// java.util.List<E>
//interface java.util.RandomAccess
//interface java.lang.Cloneable
//interface java.io.Serializable
Type[] interfaces=test.getGenericInterfaces();
for(Type type:interfaces)
{
System.out.println(type);
}
//类继承于哪个类class java.util.AbstractList
System.out.println(test.getSuperclass());
}
}