I'm trying to spot, using reflection, the 'init' method that is annotaded with the @Override annotation (or with whatever annotation), but ok, heres my example, much simplified, ofcourse Base class:
public abstract class A { public void init() { } } Then here the subclass:
public class B extends A { String bla; @Override public void init() { } public void init(String bla) { this.bla=bla; } } So the code i run to get the annotated method is this:
public static void main(String[] args) { ClassLoader c = Main.class.getClassLoader(); try { Class<?> clazz = c.loadClass("correct.path.to.class.B"); for (Method method : clazz.getDeclaredMethods()) { if (method.getName().equals("init")) { System.out.println(method.getDeclaredAnnotations().length); } } } catch (ClassNotFoundException e) { e.printStackTrace(); } } Both methods are correctly found but surprisingly, i get '0' twice when reading the length of the arrays containing the annotations, any idea whats wrong here? The method getAnnotation() gives me the same results