IG: comparing Enumerations using ==

Do you think it is a bad idea to compare enums using ==, != ?

As it stands now IG treats it as a problem


3 comments
Comment actions Permalink

No, it is legal to compare enum constants with ==.
Actually Idea generates its equals() using == for enum constants.
A request to JIRA?

Eugene.

"Alex Roytman" <nospam@hello.world> wrote in message
news:d9iote$u9$1@is.intellij.net...

Do you think it is a bad idea to compare enums using ==, != ?

>

As it stands now IG treats it as a problem

>
>


0
Comment actions Permalink

There is already an option on the inspection for whether == comparison of enums should be reported, but it's set to true by default. On consideration, I've changed this to false, but am leaving the option.

--Dave Griffith

0
Comment actions Permalink

Dave,
why do you need this option? equals() is declared final in java.lang.Enum,
so it is impossible to make a custom equality, and the general one coincides
with reference equality.

Eugene.

"Dave Griffith" <dave.griffith@cnn.com> wrote in message
news:26183444.1119699731910.JavaMail.itn@is.intellij.net...

There is already an option on the inspection for whether == comparison of
enums should be reported, but it's set to true by default. On
consideration, I've changed this to false, but am leaving the option.

>

--Dave Griffith



0

Please sign in to leave a comment.