• Post Reply Bookmark Topic Watch Topic
  • New Topic

Warning - Cast is checking against the erased type  RSS feed

 
Wally Hartshorn
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's a bit of code:


On the assignment to colNames, Eclipse is giving me this warning:
"Type safety: The cast from List to List<String> is actually checking against the erased type List"

Is there any way to write this in a way that takes care of this warning?

If I change it to this:



I get the same warning, just on the 3rd line rather than the 2nd.

Any suggestions on how to make this code warning-free?

Thanks,
Wally
 
Paul Clapham
Sheriff
Posts: 22835
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Change the PropertiesConfiguration class so that its getList() method returns a List<String> object.
 
Wally Hartshorn
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Paul Clapham:
Change the PropertiesConfiguration class so that its getList() method returns a List<String> object.


Unfortunately that's not really an option, because PropertiesConfiguration is a 3rd party class from the Apache Commons Configuration project. (True, it's open source, so technically I could modify it, but I'd rather not have to maintain my own custom version.)

Thanks for the suggestion, though.
 
Paul Clapham
Sheriff
Posts: 22835
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Then you're stuck with the warning. You can't avoid such warnings if you're interfacing generified code with legacy non-generic code.
 
Marcos R Hernandez F
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi. If Paul Clapham is right (and I believe he is), the only thing you can do is add a @suppress warnings to the method. Given the circumstances.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!