日期:2014-05-18  浏览次数:20660 次

关于元注解的问题,不得其解 求助大虾!!!
使用@Inherited元注解
注解可以被继承。
但是我下面的怎么就不行呢?
1.注解类

package cn.it.test;

import java.lang.annotation.ElementType;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
@Inherited//希望子类可以继承
public @interface myannotation{
public String value();
}


2.抽象父类

package cn.it.test;

public abstract class AbstructClas {
@myannotation("check")//对于注解属性名为value的情况,可以不写属性名
public void test() {
}
}



3.子类

package cn.it.test;

import org.junit.Test;

public class ExtendClas extends AbstructClas {
@Test
@Override
public void test() {
System.out.println("here is myannotation test!");
try {
if(this.getClass().getMethod("test",null).isAnnotationPresent(myannotation.class)){
System.out.println("这里有指定的注解!");
}else{
System.out.println("没有指定的注解!");
}

} catch (SecurityException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (NoSuchMethodException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

}

}


运行结果:
here is myannotation test!
没有指定的注解!


另外,对于借口上的方法,我也试验了,也不能继承呀!不知咋回事,请高人指教

------解决方案--------------------
没看出来你贴的这句话有问题啊?而且双引号串里面确实用的是单引号啊:
  href='#' onclick='delTr(this)'
挺正确的啊。。。