Question

So from my understanding of Java, when you write

return value;

It might actually return one of two things: the value of 'value', or a reference to 'value', depending on what type 'value' is. To my knowledge, if 'value' is a primitive data type, Java returns the value of 'value', and if 'value' is an abstract data type, like a class, then Java returns a reference to 'value'.

Now, what I'm curious about is the behavior of return with enumerations. If 'variable' is of type enum, does a value or a reference get returned?

Was it helpful?

Solution

Any Enum is an object that extends java.lang.Enum and as such you get back a reference.

OTHER TIPS

An enum is not a primitive. There is a single unique object instance for each enum 'value' per class-loader. The return type is a reference to that unique object.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top