Community
Participate
Working Groups
Build ID: I20080617-2000 Steps To Reproduce: It would be nice to have warning/error/ignore if unneeded casting is used. E.g.: class A { public void aMethod() {} } class B extends A { public void bMethod() {} } class C extends B { public void cMethod() {} } Now suppose the following: public void test(A a) { ((B) a).aMethod(); ((C) a).bMethod();// -> should be ((B) a).bMethod() } Both casts are not needed, note that this applies only if casting is directly used to execute method (without assignment to a local variable).
Unused cast warning is already available, please check: Preferences > Java > Compiler > Unnecessary code > Unnecessary cast or 'instanceof' operation > Warning Note that in the specific case you entered, the cast looks useless on the surface, but will induce some subtle changes in the generated classfile (since the actual receiver type is recorded in bytecode instruction) and can alter binary compatibility. Hence the compiler will not suggest removing the cast for this very specific pattern (which is not frequent btw).
Closing as worksforme.
Verified for 3.5M2 using I20080914-2000.