• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Warning - Cast is checking against the erased type

 
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Marshal
Posts: 28226
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Marshal
Posts: 28226
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic