google / google/error-prone

UseEnumSwitch - detection edge case (false positive)

Open
#2,521 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
7.2k
Forks
820
Avg merge
5h 9m
Merged PRs (30d)
50

Description

```java

interface Foo {
void foo();
}

enum Bar implements Foo {
Bar1, Bar2, Bar3;

void foo() { /* do something */ }
}

enum Baz implements Foo {
Baz1, Baz2, Baz3;

void foo() { /* do something else */ }
}
```

Both enums implement an interface but code like this can't be turned into an enum switch because they are two different enums:

```java
final Foo quux = getAFoo();
if (quux == Bar.Bar1) { /* some code */ }
else if(quux == Baz.Baz1) { /* some code */ }
else if(quux == Baz.Baz2) { /* some code */ }
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.