Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to Cast In Jdk5

 
Xavier Lio
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • 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.
 
Ulf Dittmer
Rancher
Pie
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
Burkhard Hassel
Ranch Hand
Posts: 1274
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic