1.wait和notify
2.通过反射机制得到类属性以及修改类属性
public static void main(String[] args) throws ClassNotFoundException, NoSuchFieldException, InstantiationException, IllegalAccessException { Class studentClass=Class.forName("ThirdWeek.day3.Student"); //获取对象的成员变量数组 Field[] fields = studentClass.getFields(); System.out.println(fields.length); Field address = studentClass.getField("address"); //获取address的修饰符,返回值为int型,说明是枚举类型 int modifiers = address.getModifiers(); System.out.println(modifiers); //通过调用modifier类查看到底是什么类型 System.out.println(Modifier.toString(modifiers)); //查看成员变量类型的名字 System.out.println(address.getType().getName()); //通过反射创建student对象的值 Object o = studentClass.newInstance(); //通过反射拿到成员变量 Field nameField = studentClass.getDeclaredField("address"); //修改成员变量的值 nameField.set(o,"realName"); System.out.println(nameField.get(o)); System.out.println(o); // }
/* 反射方法method */ public class ReflectTest2 { public static void main(String[] args) throws ClassNotFoundException, InstantiationException, IllegalAccessException, NoSuchMethodException, InvocationTargetException { Class<?> studentClass = Class.forName("ThirdWeek.day3.Student"); Method[] methods = studentClass.getDeclaredMethods(); for(Method method:methods) { //反射得到方法名 System.out.println("方法名:"); System.out.println(method.getName()); //反射得到返回值类型 System.out.println("返回值类型:"); System.out.println(method.getReturnType().getSimpleName()); //反射得到参数类型 Class<?>[] parameterTypes = method.getParameterTypes(); System.out.println("参数类型:"); for(Class C:parameterTypes) { System.out.println(C.getSimpleName()); } } //通过反射调用方法 //创建对象 Object o = studentClass.newInstance(); //得到方法 Method ssc = studentClass.getMethod("ssc", String.class, int.class); //调用方法 ssc.invoke(o,"liuwei",21); } }
/* 反射构造方法 */ public class ReflectTest3{ public static void main(String[] args) throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException, ParseException { Class<?> aClass = Class.forName("ThirdWeek.day3.Student"); //使用反射机制创建对象 //获取构造方法 SimpleDateFormat sdf=new SimpleDateFormat("yy-MM-dd HH-mm-ss"); String s="2000-10-28 10-34-22"; Date parse = sdf.parse(s); Constructor<?> constructor = aClass.getConstructor(int.class, String.class, String.class, Date.class); Object o = constructor.newInstance(21, "liuwei", "wuhan", parse); System.out.println(o); } }
3.可变长度参数
4.元注解
5.注解