I'm using an ENUM to save keys that let me get specific messages from the DB. apparently ENUMs have a limit of 2746 and my new coded got it to 2751 so i get a compilation error. Is there any way I could expand this ENUM? or will I need to use a new one for new values?
Asked
Active
Viewed 271 times
3
-
Can't you group similar enum values into their own enum? – Lino Jun 05 '19 at 09:00
-
7Refactor your code to use something other than an enum. You're way beyond what enums were designed for. – ernest_k Jun 05 '19 at 09:01
-
https://stackoverflow.com/questions/4468388/maximum-number-of-enum-elements-in-java The maximum number of enum elements is 2746. – Vitaly Jun 05 '19 at 09:03
-
it would be a quick fix lino and the problem would arrive eventually again what else could i use? ernest that's what i said vitaly – raiton Jun 05 '19 at 09:36
-
Enums are heavily abused for things that they are not intended for. An enum is defined at compile time, and the set of constants should **never** change, as of the **domain model**. This limits their use to cases like `TrafficLightColor`, `Weekday` and such. Even the [`Planet` example from the tutorial](https://docs.oracle.com/javase/tutorial/java/javaOO/enum.html) has been [messed up by Pluto!](https://web.archive.org/web/20060221115930/http://java.sun.com/docs/books/tutorial/java/javaOO/enum.html). Whatever you're trying to accomplish there: You're likely creating a maintenance nightmare. – Marco13 Jun 05 '19 at 10:29
-
this is a 10yo project. it was not my decision, but it's the first time it has led to complications.. if you don't understand what it does, why do you think you know it would create a nightmare? don't you have to understand what it is first? cause this never gave us a problem until now. – raiton Jun 05 '19 at 11:33
-
@ernest_k any idea of what we could use? – raiton Jun 05 '19 at 14:40
-
@raiton How are you using this statically? I would make these keys plain strings. If you're using an enum to limit options, then you can use something like a set of strings instead. But I'm sure you can get more useful advice from SO if you show how you're using it and what made you choose enums for it. – ernest_k Jun 05 '19 at 14:47
-
@ernest_k I didn't choose this. this is a 10yo project. I've been here for under a year basically, we use these keys to a message from the database. instead of having to create a string every time, we just do Messages.KEY_THAT_WE_WANT and boom we have a message "Message that we wanted to show" – raiton Jun 05 '19 at 15:01
-
But if `Messages.ACTUAL_STRING_YOU_WANT` was of type `String`, it would still not “having to create a string every time”, so what does using an `enum` give you here? – Holger Jun 14 '19 at 12:45
-
nothing. again. this is 10 yo project on a multibillion dollar company. it's a small part of a huge system... I didn't created it. and was hoping to find the best way to fix it. i changed it. – raiton Jul 04 '19 at 09:32