3
這是我的場景「我有一個抽象類,有許多派生類使用註釋擴展了這個抽象類。另外,我有一個抽象類的方法,它反映了所有的符號一個特定派生類「。Java反射派生類
// Here's a definition of annotation
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface SampleAnnotation {
int sample();
}
public abstract class A {
// Here's a method to reflect all annotations
// in particular derived class like B or C
@Override
public void foo() {
}}
public class B extends A {
@SampleAnnotation (sample = 1)
public void step1() {}
@SampleAnnotation (sample = 2)
public void step2() {}
}
public class C extends A {
@SampleAnnotation (sample = 1)
public void step1() {}
@Sample (stage = 2)
public void step2() {}
}
如何使用java反射來反映特定派生類(如B或C)中的所有註釋?
如果你可以在代碼中給出一個例子*,它可以更容易地確保我們正確理解問題。 – 2012-08-07 09:56:36
某些代碼總是可以幫助其他人更正確地理解你的觀點/問題 – 2012-08-07 09:56:57