Bug 70228

Summary: new compiler warning for stuff like Object o = (Integer)(new Object())
Product: [Eclipse Project] JDT Reporter: Sven Köhler <sven.koehler>
Component: CoreAssignee: Philipe Mulet <philippe_mulet>
Status: VERIFIED FIXED QA Contact:
Severity: enhancement    
Priority: P3    
Version: 3.0   
Target Milestone: 3.2 M3   
Hardware: All   
OS: All   
Whiteboard:

Description Sven Köhler CLA 2004-07-16 10:36:25 EDT
hi,

code like
  LinkedList l = ...  
  Object o = (Integer)l.getFirst();
contains a cast, that is uncessary.

What the programmer wanted to write, was either
  Integer o = (Integer)l.getFirst();
or simply
  Object o = l.getFirst();
Comment 1 Sven Köhler CLA 2004-07-16 10:40:43 EDT
OK, the cast is not unnecessary. It can produce a ClassCastException, but the like
  Integer o = (Integer)l.getFirst();
seems much better style to me.
Comment 2 Philipe Mulet CLA 2005-02-03 04:44:33 EST
That is a separate issue better handle by code reviewing tools.
Will keep it for LATER.
Comment 3 Philipe Mulet CLA 2005-09-29 15:37:38 EDT
Reconsidering. This is similar to what we already do in other cases, like
arguments in a method invocation.

foo(Object o) invoked with foo((Integer)someObj) // warning for unnecessary cast.

Comment 4 Philipe Mulet CLA 2005-09-29 15:40:13 EDT
Added support for both assignments and variable (local+field) declarations.
Fixed. Tuned existing tests.
Comment 5 Olivier Thomann CLA 2005-10-28 13:39:32 EDT
Verified for 3.2 M3 using build I20051025-0800+JDT/Core v_618a