#When should you use

1 messages · Page 1 of 1 (latest)

alpine garnet
#

records and enums? I have an idea, but i'd like others opinions as well...

regal steepleBOT
#

<@&987246399047479336> please have a look, thanks.

regal steepleBOT
#

While you are waiting for getting help, here are some tips to improve your experience:

Code is much easier to read if posted with syntax highlighting and proper formatting.

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.

alpine garnet
#

In what situations are they used?

simple terrace
#

If it's an immutable pojo, you can just make it a record

alpine garnet
#

thanks! makes sense

echo estuary
#

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?

alpine garnet
#

Yes that helped tons, ty so much!