Un uso simple de ENUM en Java ['ESP','ENG']

Como sabrán estoy aprendiendo a programar con Java pero aún estoy en lo básico, tengo conocimientos básicos y gracias a que domino otro lenguaje de programación el aprendizaje no es tan complicado como pensé que lo seria.
Hoy estuve viendo para que sirve el método reservado “ENUM”, es una palabra clave reservada para definir un tipo de dato especial que representa un conjunto fijo de constantes; de mi parte lo asimilo de igual manera que definir un objeto en JavaScript pero más fuertemente tipiado.

As you know, I am learning to program with Java but I am still in the basics, I have basic knowledge and thanks to the fact that I master another programming language, learning is not as complicated as I thought it would be. Today I was looking at what the “ENUM” reserved method is for, it is a reserved keyword to define a special data type that represents a fixed set of constants; For my part, I understand it in the same way as defining an object in JavaScript but more strongly typed.

enum2.jpg
Lo que me gusta de esto es que me permite alojar valores de datos fijos que se que no deben cambiar a lo largo del trabajo y cuando se deban modificar solo debe se hará dentro del método reservado.
Para dar una muestra sencilla de iteración con estos datos aplicare un “for” que mostrara por consola cada uno de los valores dentro del objeto y asi mismo se podrían hacer más cosas como buscar alguno en especifica u retornar el requerido según el momento.

What I like about this is that it allows me to host fixed data values ​​that I know should not change throughout the job and when they must be modified it should only be done within the reserved method. To give a simple example of iteration with this data, I will apply a “for” that will show each of the values ​​within the object through the console and also more things could be done such as searching for a specific one or returning the one required depending on the moment.


0
0
0.000
1 comments
avatar

Thanks for your contribution to the STEMsocial community. Feel free to join us on discord to get to know the rest of us!

Please consider delegating to the @stemsocial account (85% of the curation rewards are returned).

You may also include @stemsocial as a beneficiary of the rewards of this post to get a stronger support. 
 

0
0
0.000