• 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

How to Cast In Jdk5

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a function get a input of Object and I need to convert it to LinkedHashMap so if I use (LinkedHashMap)Object to cast the input the complier report errors. So what can I do to solve it.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What's the error message? What does the code look like?
 
Xavier Lio
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The error message is
Type Safty : the cast from object to LinkedHashMap<String,String> is actually checking against the erased type LinkedHashMap.

And the code is
 
Ranch Hand
Posts: 1274
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Howdy!

Casting to generic types always produces this warning. You can do nothing against it (except suppressing the warning).
The only thing you can do is accepting the warning. And perhaps take the warning as a - ehem - warning...
to check your code if the method returnning the object you cast really returns a map of the type you need.

We are always encountered with this problem e.g. in deserialization, where you get only an object back.


By the way,

welcome to the Ranch, Xavier




Yours,
Bu.
reply
    Bookmark Topic Watch Topic
  • New Topic