java - Initialize variable with annotations -


i want make own annotation initialize class field. need this:

public class myannotationclass{     map<string,string> mymap;      public string getvalue(string key) {         return mymap.get(key);     } }  @retention(retentionpolicy.runtime) public @interface myannotation {     string[] keys default {};     string[] vlaues default {}; }  public class myclass implements myinterface {     @myannotation(keys={"a","b"},values={"a","b"})     myannotationclass myannotationclass;      public myannotationclass getmyannotationclass() {         return this.myannotationclass;     } } 

i don't know how initialize variable, or i'm missing.

thanks you!

edit: i'ts little more complex that. need initialize way.

also i'm using play framework

we need more information able better.

generally speaking, annotations can processed during compilation source code or compiled classes, or can process them @ runtime. see retentionpolicy

if need initialize them during compile process need either:

  1. parse source code, rewrite variable, compile class.
  2. in case want modify .class file, need library javaassist or asm objectweb.

in both cases, need write annotation processor.

at runtime can initialize them using reflection. simplest way.


Comments

Popular posts from this blog

html - Styling progress bar with inline style -

java - Oracle Sql developer error: could not install some modules -

How to use autoclose brackets in Jupyter notebook? -