Gettining java annotations using reflection -



Gettining java annotations using reflection -

i'm trying spot, using reflection, 'init' method annotaded @override annotation (or whatever annotation), ok, heres example, much simplified, ofcourse base of operations class:

public abstract class { public void init() { } }

then here subclass:

public class b extends { string bla; @override public void init() { } public void init(string bla) { this.bla=bla; } }

so code run annotated method this:

public static void main(string[] args) { classloader c = main.class.getclassloader(); seek { class<?> clazz = c.loadclass("correct.path.to.class.b"); (method method : clazz.getdeclaredmethods()) { if (method.getname().equals("init")) { system.out.println(method.getdeclaredannotations().length); } } } grab (classnotfoundexception e) { e.printstacktrace(); } }

both methods correctly found surprisingly, '0' twice when reading length of arrays containing annotations, thought whats wrong here? method getannotation() gives me same results

check documentation @override , retentionpolicy. basically, @override annotation not available @ runtime, it's source annotation.

http://docs.oracle.com/javase/7/docs/api/java/lang/annotation/retentionpolicy.html

http://docs.oracle.com/javase/7/docs/api/java/lang/override.html

java reflection annotations

Comments

Popular posts from this blog

java Multi query from Mysql using netbeans -

c# - DotNetZip fails with "stream does not support seek operations" -

c++ - StartServiceCtrlDispatcher don't can access 1063 error -