This one is for Enum type.
As Java Doc states -
" An enum type is a special data type that enables for a variable to be a set of predefined constants. The variable must be equal to one of the values that have been predefined for it. Common examples include compass directions (values of NORTH, SOUTH, EAST, and WEST) and the days of the week.You should use enum types any time you need to represent a fixed set of constants. "
Ok, that sounds cool, but can we have a working Demo that can depict where can we use it further?
Surely we can, and here is one example.
We have a scenario here -
A superhero scenario.
Superman, who is not willing to reveal his real name, Batman, hmmm we all know when he wants and he doesn't want to reveal his real name, and Deadpool who is not invited in the party, yet trying to sneak in.
So can we cater to the requirements here -
1. Provide Superman the data hiding.
2. Provide Batman his real name revealed, when he wants.
3. Stop Deadpool from ruining the party.
Just have a glance at the code, the comments are included to narrate what's going on -
Well, after this action, here is the aftermath, I mean the logs -
You selected - SUPERMAN
Real Name - SUPERMAN
You selected - BATMAN
Real Name - Bruce Wayne
ID verified, it's - BATMAN
Wade Wilson AKA Deadpool trying to sneak in...
Entry Allowed? null
For full code/ project, visit -
So that's it for now. Will meet you soon with some other interesting topics.