• Post Reply Bookmark Topic Watch Topic
  • New Topic

Access non-static values from enum  RSS feed

 
Anwarul Kabir
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am getting null on userAccess and when debugging i noticed that static method is getting called after the constructor. can some one please help me fix my code here? thanks.

 
Rob Spoor
Sheriff
Posts: 21135
87
Chrome Eclipse IDE Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Move the Sets and the static initializer block into enum UserAccessCategory instead. Of course you also need to modify the GatewayStatus constructors to use UserAccessCategory.Nipr instead of GatewayStatus.Nipr, etc.

Also, two hints:
1) Use EnumSet instead of HashSet. It's just a bit better for enums. Similarly, EnumMap is the best choice for a Map with an enum as key type.
2) Right now you can modify GatewayStatus.AV by modifying the Set returned by Gateway.PG.getUserAccess(). It's better to make all of the Sets unmodifiable:
 
Anwarul Kabir
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Spoor wrote:Move the Sets and the static initializer block into enum UserAccessCategory instead. Of course you also need to modify the GatewayStatus constructors to use UserAccessCategory.Nipr instead of GatewayStatus.Nipr, etc.

Also, two hints:
1) Use EnumSet instead of HashSet. It's just a bit better for enums. Similarly, EnumMap is the best choice for a Map with an enum as key type.
2) Right now you can modify GatewayStatus.AV by modifying the Set returned by Gateway.PG.getUserAccess(). It's better to make all of the Sets unmodifiable:


That did the trick. Thank you so much.
 
Rob Spoor
Sheriff
Posts: 21135
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!