Combining Java censuses with dotted syntax (enum.value1.value2)?

I am looking at some existing (and working) code and came across a line like this:

if (someObject.getStatus() == SomeEnum.VALUE1.VALUE2) { ... }

Where SomeEnum is a simple enumeration that looks like this:

public enum SomeEnum {
    VALUE1,
    VALUE2,
    VALUE3,
    ...
}

private SomeEnum() {}

Now, what makes this comparison higher? More precisely, what does the combination of the two enum values ​​do? I was surprised not to see any warnings or errors because of this line, as I assumed that it was simply wrong. However, it compiles and works very well. Can someone enlighten me on what this will do?

+4
source share
3 answers
if (someObject.getStatus() == SomeEnum.VALUE1.VALUE2) { ... }

equivalently

if (someObject.getStatus() == SomeEnum.VALUE2) { ... }

== will compare the memory address on both sides for non-primitive types.

+2
source

, IDE, ​​ Eclipse, , VALUE2 . javac -Xlint:all . , SomeEnum.VALUE1.VALUE2 SomeEnum.VALUE2. .

+5

Do not use Enum in android http://developer.android.com/training/articles/memory.html#Overhead

(I could not make comments due to a reputation problem, so I wrote here.)

+2
source

All Articles