RTC.CALLThe 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: public class Apple { 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 19 public class Instruction { 10 } 11 public class JmpInstruction extends Instruction { 12 private final Number address; 13 protected JmpInstruction(Number address) { 14 this.address = address; 15 } 16 public Number getAddress() { 17 return address; 18 } 19 } 20 public class ShortJmpInstruction extends JmpInstruction { 21 public ShortJmpInstruction(Byte address) { 22 super(address); 23 } 24 } 25 // ... 26 public void visitInstruction(JmpInstruction i) { 27 if (i instanceof ShortJmpInstruction) { 28 // cast is not necessary here 29 Number address = 30 ((ShortJmpInstruction) i).getAddress(); 31 print(address); 32 } 33 // then visit other instrucrions.. 34 } 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' |