Reports type casts that are overly strong. For instance, casting an object to ArrayList when casting it to List would do just as well.

Note: much like the Redundant type cast inspection, applying the fix for this inspection may change the semantics of your program if you are intentionally using an overly strong cast to cause a ClassCastException to be generated.

Example:

  interface Super {
    void doSmth();
  }
  interface Sub extends Super { }

  void use(Object obj) {
    // Warning: ((Super)obj).doSmth() could be used
    ((Sub)obj).doSmth();
  }

Use the checkbox below to ignore casts when there's a matching instanceof check in the code.