Bug 70228 - new compiler warning for stuff like Object o = (Integer)(new Object())
Summary: new compiler warning for stuff like Object o = (Integer)(new Object())
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.0   Edit
Hardware: All All
: P3 enhancement (vote)
Target Milestone: 3.2 M3   Edit
Assignee: Philipe Mulet CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-07-16 10:36 EDT by Sven Köhler CLA
Modified: 2005-10-28 13:39 EDT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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