#When should you use
1 messages · Page 1 of 1 (latest)
<@&987246399047479336> please have a look, thanks.
While you are waiting for getting help, here are some tips to improve your experience:
If nobody is calling back, that usually means that your question was not well asked and hence nobody feels confident enough answering. Try to use your time to elaborate, provide details, context, more code, examples and maybe some screenshots. With enough info, someone knows the answer for sure.
Don't forget to close your thread using the command </help-thread close:1027500463647621170> when your question has been answered, thanks.
for what ?
In what situations are they used?
If it's an immutable pojo, you can just make it a record
thanks! makes sense
Enums are best used when you need a variable with a limited set of possible values that are unchanging during the programs runtime. They are safer than strings and clearer than ints.
Examples are weekdays. there are always 7 weeksdays. But you could also use it for the state of objects or to seperate them into different categories.
You can assign stings to them. but if you create an object with 2 string values, a typo can lead to errors. and even if you use refrence strings, you could still mix up the strings and assign the month "Tuesday". Enums prevent both of these.
Also I am not sure, but I think they are much more memory efficient.
And at last: Enums allow you to use EnumMaps.
Does that help you?
Yes that helped tons, ty so much!