As a beginner in Java I was introduced to enums and that just got me really confused with type declaration. I would like to share what I know, so that one of you might find a problem in the way I think.
I have learned that there are two datatypes, primitive datatypes and object datatypes. When declaring a variable, you first write the datatype and then the identifier of the variable.
When I declared a datatype int variable, I have the following idea in my head:
int a = 1; int as datatype references to the primitive integer datatype.
When I declared a datatype Integer variable, I have the following idea in my head:
Integer b = 1; Integer as datatype references to the object datatype (that in this case is an instance of the class integer)
When I declare an enumerator variable, I have the following idea in my head:
enum C {EXAMPLE1, EXAMPLE2}; No clue what enum references to.. Is it an object datatype and an instance of class enum? If so, where is the capital letter E in enum.
So here the problem starts. I have learned that enum is not a primitive datatype, so the only posibility is that it is an object. But I have also learned that declaring an object of a class as datatype means that the identifier should start with a capital letter like Integer, Boolean etc. I can however declare an enum without a capital letter. Does this mean it is not an object? Or is an enumerator just a keyword like class and not a variable datatype like I assumed it to be.
If enum is not a variable datatype but rather a keyword like class then I wonder if the following mindset is correct:
enum Test {EXAMPLE1, EXAMPLE2}
Test e = Test.EXAMPLE; Does Test reference to the object datatype? (That
in this case is an instance of the enumerator Test)
If Test is an instance of the enumerator Test, how is this possible? I only thought it was possible to create objects from classes but I have also read something about constructors in enumerators.
I have been looking for answers on this question for a couple of hours now with no success. I hope I haven't messed up your head by now. But I truely hope that there is someone that can make some sense of this and actually help me out.