There's nothing special about enums here. You'll see the exact same behaviour if you use strings or any type, basically.
Your two Test
objects are entirely separate. When you write:
t2.enumValue = TestEnum.THREE;
you're changing the value of the enumValue
field within the second object to be a reference to the object referred to by TestEnum.THREE
.
The two enumValue
fields (one via t1
and one via t2
) are entirely separate. Changing one field doesn't change another.
Now, if instead you made your enum mutable (which I would strongly discourage) and changed your code to something like this:
t2.enumValue.someMutableField = "a different value";
... then that would be visible via t1.enumValue
, because they both refer to the same object.
It's really important to differentiate between changing a field within an instance of Test
, and changing a field within an object that you happen to reach via an instance of Test
.
Again, this really isn't about enums. You may well find it's simpler to get your head round the idea by changing the enumValue
field to a String
field, and experimenting that way.