您的位置:首页 > 编程语言 > Java开发

java注解,在继承时会被子类覆盖,会被子类覆盖的函数覆盖,如果继承的子类不写注解的话,默认没有注解,即不会继承父类的注解

2015-01-12 15:05 429 查看
package Test;

import java.lang.reflect.Method;

@person2(Integer_value = 0, b = 0)
public class Annotation {
@person(Integer_value = 12, b = 12, value = "method1")
public void method1(){

}
@person(Integer_value = 24, b = 123, value = "method2")
public void method2(){

}
@person(Integer_value = 0, b = 0,value ="method3")
public void method3(){

}
public static void main(String[] args){
// TODO Auto-generated method stub
Class c=Annotation.class;
Method[] m=c.getMethods();
for(Method t:m){
if(t.isAnnotationPresent(person.class)){
person name=t.getAnnotation(person.class);
System.out.println(name.value());
System.out.println(name.b());
System.out.println(name.Integer_value());

}
}
Class cc=Annotation.class;

System.out.println(c.getAnnotation(person2.class));
class ext extends Annotation{

public void method3(){

}
}
Class e=ext.class;
Method[] me=e.getMethods();
for(Method t:me){
if(t.isAnnotationPresent(person.class)){
person name=t.getAnnotation(person.class);
System.out.println(name.value());
System.out.println(name.b());
System.out.println(name.Integer_value());
}
}
}

}

输出结果

method1
12
12
method2
123
24
method3
0
0
@Test.person2(value=def, Integer_value=0, b=0)
method1
12
12
method2
123
24
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐