Bug 28902 - Add warning for downcasting to subclass in a superclass
Summary: Add warning for downcasting to subclass in a superclass
Status: CLOSED WONTFIX
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 2.1   Edit
Hardware: All All
: P3 enhancement (vote)
Target Milestone: 3.0 M5   Edit
Assignee: JDT-Core-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2002-12-29 12:07 EST by Max Rydahl Andersen CLA
Modified: 2009-08-30 02:19 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 Max Rydahl Andersen CLA 2002-12-29 12:07:21 EST
Just came to think of this "common beginner" codeing error which would be nice 
to have an warning/error for.




Example (derived from real wildlife code):




abstract class Base {


   ...


 


   doSomething(Base b) {


      SubBase x = (SubBase)b;  <= NOT GOOD! Needs a warning/error!


      <do something with x>


   }


}




class SubBase extends Base {




}




It is totally legit code, but people doing it should be informed about their 
"ignorance" :)
Comment 1 Dirk Baeumer CLA 2002-12-31 10:05:52 EST
No clear if this should be covered by a compiler or by some sort of code 
convention checking tool. Moving to core for commenting (IMO this shouldn't be 
covered by the compiler).
Comment 2 Philipe Mulet CLA 2003-01-08 05:57:29 EST
I am not a big fan either of having this one reported by the compiler (even 
optionally). 

May reconsider post 2.1 if more votes are added.
Comment 3 Max Rydahl Andersen CLA 2003-01-08 06:27:24 EST
Ok :)




(but just curious - what is the difference between this warning and e.g. a 
warning against x = x; - isn't both just a BAD thing ?)


Comment 4 Philipe Mulet CLA 2003-10-30 04:43:44 EST
Closing since support for unnecessary cast/instanceof got added a while ago in 
3.0 stream.
Comment 5 Denis Roy CLA 2009-08-30 02:19:28 EDT
As of now 'LATER' and 'REMIND' resolutions are no longer supported.
Please reopen this bug if it is still valid for you.