RTC.CALL

The Redundant Type Cast (RTC) warning appears when one adds cast to some class while invoking a method which is defined in a more general class. An example is below:

Copy
public class Apple { 
  public String someAppleToString(Object o) { 
  return ((Apple) o).toString();
  }
}

In this example, a type-cast to Apple is redundant, because Apple class does not redefine toString() method and Object's method is actually used. The RTC.CALL warning appears when one adds cast to some class while invoking a method which is defined in a more general class.

Example 1

Copy
      public class Instruction {
     }
     public class JmpInstruction extends Instruction {
         private final Number address;
         protected JmpInstruction(Number address) {
             this.address = address;
         }
         public Number getAddress() {
             return address;
         }
     }
     public class ShortJmpInstruction extends JmpInstruction {
         public ShortJmpInstruction(Byte address) {
             super(address);
         }
     }
     // ...
     public void visitInstruction(JmpInstruction i) {
         if (i instanceof ShortJmpInstruction) {
             // cast is not necessary here
             Number address =
                     ((ShortJmpInstruction) i).getAddress();
             print(address);
         }
         // then visit other instrucrions..
     }

RTC.CALL is reported for line 30: Type cast from 'com.klocwork.jdefects.checkers.ast.samples.RTC_CALL_Sample_1$JmpInstruction' to 'com.klocwork.jdefects.checkers.ast.samples.RTC_CALL_Sample_1$ShortJmpInstruction' is redundant because method 'getAddress' is defined in 'com.klocwork.jdefects.checkers.ast.samples.RTC_CALL_Sample_1$JmpInstruction'