+ 2

Enum question java

what is the use of enum?is it a class or object?

2nd Nov 2017, 5:37 PM
oyl
4 odpowiedzi
+ 5
You can think of it as a list of named constants. For example, you could have an enum for the days of the week, months of the year, seasons of the year, etc.. As we both know, each of those sets are constants and won't change, so we can use an enum to define that. As another example, recently I've been creating some server/client software for a new system I'm introducing to our intranet at work. I've set up a classes on the client side and server side to handle the packets of data that'll be sent back & forth between the server and client. I created enums on both ends that'll hold onto the various headers I'll use for the packets. This is something that I want to be constant/the same between client & server so that they'll properly handle the information while talking with each other. I'd poke around and research more into it though. In my opinion, enums are a lot more useful in Java than the other languages that I know, and you can do more things with it.
2nd Nov 2017, 5:52 PM
AgentSmith
+ 4
https://docs.oracle.com/javase/tutorial/java/javaOO/enum.html https://docs.oracle.com/javase/tutorial/java/javaOO/classes.html https://docs.oracle.com/javase/tutorial/java/javaOO/objects.html ^Instead of me typing out and explaining what enums, classes, and objects are, here is the official information on all three. Read through **ALL** of the documentation and you'll obtain a better understanding of it. Just like anything, if you choose to not read through all of it, you're choosing to not know more about it.
2nd Nov 2017, 6:21 PM
AgentSmith
+ 1
why is it different from creating object?
2nd Nov 2017, 6:01 PM
oyl
+ 1
An enum is a data type (just like a class is a DataType, not an object) that allows a variable (of that type) to be a set of predefined constant values. You can create objects of an enum data type.
19th Dec 2017, 1:01 PM
Danilo
Danilo - avatar