Dynamic Values in annotations -


i writing annotation based framework project. earlier passing static text in annotations , working fine.here sample code:-

public class myclass{    @myannotation(name="hello world")    private int variable;    @myannotation(name="again hi")    private int variable1; } 

because of changes, need use final variables value method. know annotation can not take dynamic values. fix now. passed number in name values , when parsing annotation pass number in predefined method , returns value on basis of number. here code snippet that:-

public class myclass{   private static final string finalvar1 = getvalue("hello world");   private static final string finalvar2 = getvalue("again hi");   @myannotation(name="1")   private int variable;   @myannotation(name="2")   private int variable2;    public string getconvetedvalue(string value){     if(value!=null && value.equals("1")){         return finalvar1;     }else if(value!=null && value.equals("2")){        return finalvar2;     }   } } 

so in above example getconvertedvalue called annotation parser using reflection , parser pass number method fetched annotation.

please suggest me better solutions problem.


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -