Annotation作用:
不是程序本身,可以对程序做出解释
可被其他程序读取
Override:重写
Mapper:写在Dao层接口上,放入IOC容器
select insert update delete : 增删改查接口
Deprecated:不推荐使用但能用的内容(或者存在更好的方式)
元注解: 注解其他的注解
仅4类
Target:注解的适用范围
Retention:表示需要在什么时候还有效 (一般都是Runtime,运行时)
Document:说明该注解被包含在javadoc中
Inherited:说明子类可以继承父类中的该注解
自定义注解:@interface
若无默认值 则必须给注解赋值
public class test03 { @myAnnotation(value = "test03") public void test03(){ System.out.println("test03"); } } //自定义注解 @Target({ElementType.METHOD,ElementType.TYPE}) @Retention(RetentionPolicy.RUNTIME) @interface myAnnotation { //注解的参数: 参数类型 + 参数名 String value() default ""; }反射(Reflection):
是Java被视为动态语言的关键
一个类在内存中只有一个class对象,一个类被加载后,类的整个结构都会被封装在Class对象中
获得Class类的实例
Class c3 = Student.class; System.out.println(c3.hashCode()); Class c2 = Class.forName("com.study.mapper.Student"); System.out.println(c2.hashCode()); //获得父类类型 Class c4 = c1.getSuperclass(); System.out.println(c4);类的加载过程:
顺序:
class A{ static { System.out.println("A类静态代码块初始化"); m=300; } static int m =100; public A() { System.out.println("A类构造方法初始化"); } }A类静态代码块初始化(先加载static)
A类构造方法初始化(再加载构造器)
100
几种常见用法
public class test03 { public static void main(String[] args) throws ClassNotFoundException { Class c1 = Class.forName("com.study.mapper.Student"); System.out.println(c1.getName()); System.out.println(c1.getSimpleName()); Class c2 = Class.forName("com.study.mapper.Person"); Field[] field = c1.getFields(); for (Field f : field) { System.out.println(f); } Field[] field1 = c2.getDeclaredFields(); for (Field f : field1) { System.out.println(f); } Method[] method = c1.getMethods(); for (Method m : method) { System.out.println(m); } } }