File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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


JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "How to Cast In Jdk5" Watch "How to Cast In Jdk5" New topic
Author

How to Cast In Jdk5

Xavier Lio
Greenhorn

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
Marshal

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


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

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
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.


all events occur in real time
 
GeeCON Prague 2014
 
subject: How to Cast In Jdk5