This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes How to Cast In Jdk5 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "How to Cast In Jdk5" Watch "How to Cast In Jdk5" New topic

How to Cast In Jdk5

Xavier Lio

Joined: Oct 07, 2007
Posts: 9
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

Joined: Mar 22, 2005
Posts: 41066
What's the error message? What does the code look like?

Ping & DNS - my free Android networking tools app
Xavier Lio

Joined: Oct 07, 2007
Posts: 9
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

Joined: Aug 25, 2006
Posts: 1274

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


all events occur in real time
It is sorta covered in the JavaRanch Style Guide.
subject: How to Cast In Jdk5
Similar Threads
string to object
ordering of elements in Hashtable
Map mock question
Casting problem with LinkedHashMap !!