The Tipos Enum are not meant to be dynamically added/changed/removed. Quote documentation of Java itself:
You should use Enum types any time you need to represent a Fixed set of constants
In other words, you should use enum
to represent an intended/fixed/invariable set of constants.
To represent some information that are immutable, as the days of the week (Monday, Tuesday, etc.) enumerators are very useful. After all, what is the possibility of adding a new day of the week to our calendar? :)
In your case, you need to choose to keep these categories dynamically, out of the compiled code of your project. That is, out of a enum
. Usually this is done using a database that, in your case, could have a table categoria
to be able to register the supermarket product categories and read these categories from a query to this table in the database.
Thank you very much. The database is ready I had doubts about using Enum. I’m glad it won’t be hard to replace rsrsrsrsrsr.
– Stênio Barroso de Moraes