• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to set string value parameters in Annotaions without hardcoding

 
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Take the following made up example:


The name parameter can only be assigned a constant value. However I do not like hard-coding this name. What if I need to use the same name somewhere else? I would have to hard code it again and then possibly introduce a bug if one hard-coded value was updated but not the other.

Is the only solution to use a constant string variable?

What if he example was more complex and I have several of the same annotations with each string a little different but all fit into the same "group". Like a list of enumerated values.



Seems like a good solution would be to create an Enum called 'Color' but again the toString() method of enum does not return a constant right.

So now I am back to a string but in this case a constant list of strings?

Anyone have any good advice??
 
reply
    Bookmark Topic Watch Topic
  • New Topic