package baseApi;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class ClassApi {
public static void main(String[] args) {
List<String> list = new ArrayList<>();
String string = list.getClass().toString();
Class<?> class1 = list.getClass();
//System.out.println(class1.toString()); //class java.util.ArrayList
String[] a = {"2","2"};
string = a.getClass().toString();
//System.out.println(string); // class [Ljava.lang.String;
//System.out.println(class1.toGenericString()); //public class java.util.ArrayList<E>
//System.out.println(String.class.toGenericString());
boolean b = List.class.isInstance(list); // 等用于 list instanceof List
//System.out.println(b);
b = ArrayList.class.isAssignableFrom(list.getClass()); //
System.err.println(b);
string = List.class.toString();
System.out.println(string);
b = List.class.isInterface();
System.out.println(b);
b = a.getClass().isArray();
System.out.println(b);
System.out.println(a.getClass().toString());
int n = 2;
b = int.class.isPrimitive(); // 基本类型
System.out.println(b); // true
System.out.println(int.class.toString()); // int
b = Override.class.isAnnotation();
System.out.println(b);
System.out.println(Override.class.toString());
String.class.getName();
System.out.println(a.getClass().getName()); //
string = ArrayList.class.getSuperclass().toString(); // Super Class is AbstractList
System.out.println(string); // class java.util.AbstractList
string = String.class.getPackage().toString();
System.err.println(string); //package java.lang, Java Platform API Specification, version 1.8
Class[] classes = ArrayList.class.getInterfaces();
System.out.println(Arrays.toString(classes));
//[interface java.util.List, interface java.util.RandomAccess, interface java.lang.Cloneable, interface java.io.Serializable]
n = String.class.getModifiers(); //
System.out.println(n); //17
string = Arrays.class.getSimpleName();
System.out.println(string); // Array
System.out.println(Arrays.class.getTypeName()); //java.util.Arrays
// getDeclaredFields 本类字段
Field[] fields = String.class.getFields(); // Public Fields 以及父类
for(Field field: fields) {
System.out.println(field.getName());
}
//getDeclaredMethods 本类方法
Method[] methods = String.class.getMethods(); // Public Methods
for(Method method: methods) {
System.out.println(method.getName());
}
}
}
Class 详解
最新推荐文章于 2020-04-26 19:04:15 发布