reflection - Understanding Java annotations -


i've looked around bit, , i'm failing understand parts of how java annotation work.

all examples i've seen far create annotation, have main method runs through classes in project using reflection. stuff , make annotation work.

however i'm failing understand how works if want make annotation project jar can include in project, jackson, guice, hibernate, etc. main method wouldn't work in case, right?

i've looked tutorials on how make annotation done jar project can include, haven't found yet. ideally i'd able use inside web framework such spring or play.

there 2 main kinds of annotation want think about. first kind runtime annotation. example @jsonignore in jackson.

class test {     @jsonignore private int num;     private string str; } 

when user passes test library code code, use getclass() inspect annotations , magic. is, when user does

mylibrary.dosomething(something) 

you call something.getclass() , loop on annotations somewhere inside dosomething().

the other kind compile time annotations, processed annotation processors. example @getter project lombok:

class test {     @getter private final string name; } 

the annotation processor turns into

class test {     private final string name;     public string getname() { return name; } } 

this done when user invokes javac (right before javac compilation) , has library jar on classpath. examples


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -