Community
Participate
Working Groups
I2003-10-07 consider the following class: public class Balk { public void foo(Object bar) { System.out.println(((Object)bar).toString()); } } Clearly, the cast to Object in the println is unnecessary. This is not flagged by the compiler, even though the "unnecessary cast or instanceof" is selected on the preference page (either warning or error).
It seems that we tag the cast expression to check the unnecessary cast later using: if (this.receiver instanceof CastExpression) this.receiver.bits |= IgnoreNeedForCastCheckMASK; // will check later on in the MessageSend type resolution (toString() call). Then inside the cast expression, we detect the unnecessary cast, but we don't report it.
Problem occurs as well for field references.
Added regression tests: CastTest#test024 CastTest#test025 Fixed. Will be released publicly once M4 is declared
Verified