I've been generifying some Java code that used lots of casts, and now most of them are redundant and unnecessary.
It could be very tedious to inspect all the usages of the code to remove them, so: are there any tools to help to identify (and remove) superfluous casts?
If you're using Android Studio it's an easy fix: Analyze > Code Cleanup
This can be automatically done using Eclipse Helios. In your project, go to Properties -> Java code Style -> Clean Up. There, edit a profile, go to the "Unnecessary Code" Tab and check "Remove unnecessary casts". Then right-click your source root and klick Source-> Clean up. Job done.
In Eclipse, under "warnings and errors" you can set "Unnecessary cast or instanceof operations" to be "Warn" or "Error" rather than "Ignore". That should help you find them very quickly, although it won't clean them up for you.
But you can also set a "Save" action configured with an "Additional action" of "Remove unnecessary casts".
And you can right-click on an area of Package Explorer, select "Clean up..." and configure that with a "Remove unnecessary casts" action.
So basically this should be simple :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With