6
In a project I thought of exchanging whole ones for enum
but a colleague told me that enum
s are anti performatic.
6
In a project I thought of exchanging whole ones for enum
but a colleague told me that enum
s are anti performatic.
7
Yes, the enumeration of Java is a class, so an object heavier than a pure and simple number, and even worse, a class is allocated in the heap that puts pressure on Garbage Collector, as any object placed there.
But it is not that this will change the conditions of its application too much, at least in almost all situations, there may be some case outside the curve that is relevant. At the same time, Java is "anti performatic", his colleague said this?
Java doesn’t value efficiency in everything it does. That doesn’t mean that Java is as slow as some people think. It alone is not a language concerned to the extreme with efficiency. It consumes memory like no one else, so a enum
more or less won’t change much.
Do you need all this efficiency for this case? If you don’t need can use the enum
even if it’s not a 10, it’s still close to that. If you need efficiency don’t use it, but I doubt that’s the case.
And see if you use the enum
will make the code really more readable, otherwise you don’t have to worry either. I don’t like the style that some people use it by writing their members in ALL_CAPS.
Today it is 8 or 80, but Java moving more to efficiency soon (although they have been promising for about 5 years) soon will have a type per custom value that will give to simulate a enum
more efficient, maybe even create a new enum
better. Today the 100% efficient solution is to use an integer.
The enum
Java is more than a enum
, it is very powerful but inefficient in the current form.
Browser other questions tagged java performance kotlin enums
You are not signed in. Login or sign up in order to post.
Thank you so much for the answer! Clarified the doubt I had.
– Louix Dev
uma classe é alocada no heap que coloca pressão no garbage collector
. Out of curiosity, do you have any reference (article/question) that already measured this? I thought thatenum
was light enough to be irrelevant to the difference.– Rafael Tavares
I speak of irrelevance, but it is not zero.
– Maniero