문제

I'm replacing a group of String constants with an enum, but the constants weren't used everywhere they should have been. So we're replacing a lot of someValue.equals(FOO_CONST) with someValue == MyEnum.FOO. It's easy to fix all the places where they were used--just delete the constants and the compiler tells you where the problems are. However, there are also bits like "foo".equals(someValue), which the compiler can't identify as an error after the change is made.

Is there any way I can detect potential bugs caused by any of these inline literals that get missed during the conversion? (I'm using eclipse)

도움이 되었습니까?

해결책

FindBugs reports bugs for calls to equals(Object) when the two objects are not of the same type, which handles this problem nicely.

They will show up in the Bug Explorer under:

  • Scariest
    • High confidence
      • Call to equals() comparing different types
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top