Win a copy of Rust Web Development this week in the Other Languages forum!
  • 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:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

ENUm name starting with numeric value?

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i have set of contants in Enum class, i got to add a new contants to it but they start with numeric value something like 8SS and this gives me error Please suggest

public enum MidCheck {8SS("SAM") ;


This is giving me error.
Note i cannot change the COnstant name as its refered in mapped.
 
Rancher
Posts: 4801
50
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
They can't start with a number.
They have the same naming rules as variables, so they must start with a letter, '$' or underscore.
 
siddu math
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Now what i m trying to do is changed the enum name like EIGHTSS, but need to make it 8SS before sending it to the map, how can do that



Map<String, String> SSS = new HashMap<>();

       SSS = Arrays.stream(MidCheck.values()).collect(Collectors.toMap(Enum::name, MidCheck::getValue));
 
Dave Tolls
Rancher
Posts: 4801
50
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Give your enum a method to retrieve the correct code:
 
siddu math
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yes i got it. i have added an '_' and then while retreviewing that value in map have removed that '_'
 
Saloon Keeper
Posts: 24828
172
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Actually, an underscore isn't the best character to use here.

While it's technically legal to do so, names beginning with underscore often denote "magic" or "invisble" items. Beginning with two underscores is even worse.

I typically use a common prefix on my enum values though that's partly a carry-over from langiuages where enums can be accidentally mis-used niore easily.

So I'd probably name my enums something like code8SS and codeFoo.
 
reply
    Bookmark Topic Watch Topic
  • New Topic