• Post Reply Bookmark Topic Watch Topic
  • New Topic

Legacy Code to Generics  RSS feed

 
Ranch Hand
Posts: 244
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I have the following code.



Now if I make it to generic for 1.5 it becomes as below:


it is giving a warning : Type safety: Unchecked cast from Object to Vector<Stock>..As because clone() method returns Object that is why the warning arises...How to remove that warning?

Please suggest.

 
Sheriff
Posts: 21378
92
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Unless you can change the signatures of the methods all that remains is using @SuppressWarnings("unchecked"). you should be careful with that; any use of it should be as limited as possible (so if possible use it only with local variables) and well-documented why the cast is safe.
 
When I was younger I felt like a man trapped inside a woman’s body. Then I was born. My twin is a tiny ad:
Why should you try IntelliJ IDEA ?
https://coderanch.com/wiki/696337/IntelliJ-IDEA
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!