An item contains a limited number of constants.
Using enum to ensure something can only be a limited number of values.
In this lesson, you're going to create an enum.
An enum defines a collection of static final constants.
Using Inam to ensure a variable can only be a limited number of values.
The size of a shirt should be limited to three values, small, medium or large.
But what if the caller writes something like Wambo?
They surely can assizes of type string so it can be anything.
Then you might think that's OK.
We could just apply exception handling if the caller writes anything bad.
Yeah, but why do any of that?
From the start, we just use an item to insure this variable can only be a limited number of values.
So inside the shirt class, we're going to create a public item called size that defines three static
final constants, small, medium, large.
This is how you create an item.
All you have to do is make sure to always capitalize constants inside of an item now by default, every
value inside of an enormous final.
These values can never be changed.
Basically, an item is just a collection of final values.
OK, now the problem with the size is that it's a strength, which means it can be any type of value,
we're going to make it an enum type so that it's limited to only three.
And now the constructor needs to receive an item constant.
And now you're going to have to regenerate the getters and setters.
Now, back in Maine, an enum is implicitly static, that means we can access it directly from the class.
And now I can only give the shirt one of three values, small, medium or large, I'm going to give
it a size of small.
And now I can print the object.
And everything works beautifully.
You limited the size field to three possible values.
Use an enum to ensure something can only be a limited number of values.