Afrikaans
Akan
Albanian
Amharic
Arabic
Armenian
Azerbaijani
Basque
Belarusian
Bemba
Bengali
Bihari
Bosnian
Breton
Bulgarian
Cambodian
Catalan
Cebuano
Cherokee
Chichewa
Chinese (Simplified)
Chinese (Traditional)
Corsican
Croatian
Czech
Danish
Dutch
English
Esperanto
Estonian
Ewe
Faroese
Filipino
Finnish
French
Frisian
Ga
Galician
Georgian
German
Greek
Guarani
Gujarati
Haitian Creole
Hausa
Hawaiian
Hebrew
Hindi
Hmong
Icelandic
Igbo
Indonesian
Interlingua
Irish
Italian
Japanese
Javanese
Kannada
Kazakh
Kinyarwanda
Kirundi
Kongo
Korean
Krio (Sierra Leone)
Kurdish
Kurdish (Soranรฎ)
Kyrgyz
Laothian
Latin
Latvian
Lingala
Lithuanian
Lozi
Luganda
Luo
Luxembourgish
Macedonian
Malagasy
Malay
Malayalam
Maltese
Maori
Marathi
Mauritian Creole
Moldavian
Mongolian
Myanmar (Burmese)
Montenegrin
Nepali
Nigerian Pidgin
Northern Sotho
Norwegian
Norwegian (Nynorsk)
Occitan
Oriya
Oromo
Pashto
Persian
Polish
Portuguese (Brazil)
Portuguese (Portugal)
Punjabi
Quechua
Romanian
Romansh
Runyakitara
Russian
Samoan
Scots Gaelic
Serbian
Serbo-Croatian
Sesotho
Setswana
Seychellois Creole
Shona
Sindhi
Sinhalese
Slovak
Slovenian
Somali
Spanish
Spanish (Latin American)
Sundanese
Swahili
Swedish
Tajik
Tamil
Tatar
Telugu
Thai
Tigrinya
Tonga
Tshiluba
Tumbuka
Turkish
Turkmen
Twi
Uighur
Ukrainian
Urdu
Uzbek
Vietnamese
Welsh
Wolof
Xhosa
Yiddish
Yoruba
Zulu
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.
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.