Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / November 2006

Tip: Looking for answers? Try searching our database.

Unchecked cast warning?

Thread view: 
Knute Johnson - 01 Nov 2006 20:12 GMT
I'm trying to read a Hashtable from an ObjectInputStream and getting an
Unchecked cast warning in the compiler.

Hashtable<Integer,String[]> table =
 (Hashtable<Integer,String[]>)ois.readObject();

com\knutejohnson\redrock\scores\ScoresServer.java:209: warning:
[unchecked] unch
ecked cast
found   : java.lang.Object
required: java.util.Hashtable<java.lang.Integer,java.lang.String[]>
         (Hashtable<Integer,String[]>)ois.readObject();
                                                    ^
1 warning

Where am I going wrong here?

Thanks,

Signature

Knute Johnson
email s/nospam/knute/

Thomas Hawtin - 01 Nov 2006 20:49 GMT
> I'm trying to read a Hashtable from an ObjectInputStream and getting an
> Unchecked cast warning in the compiler.
>
> Hashtable<Integer,String[]> table =
>  (Hashtable<Integer,String[]>)ois.readObject();

This seems to be a common problem...

http://groups.google.com/group/comp.lang.java.programmer/tree/browse_frm/thread/
7b7457c1598473ba/5d022881ad375d93#doc_06f9e33d0ffd3e41


     /**
      * @throws ClassCastException
      * @see ObjectInputStream#readObject
      */
     @SuppressWarnings("unchecked")
     static <T> readObject(
         ObjectInputStream in
     ) throws IOException, ClassNotFoundException {
         return (T)in.readObject();
     }

Tom Hawtin
su_dang@hotmail.com - 01 Nov 2006 21:01 GMT
> > I'm trying to read a Hashtable from an ObjectInputStream and getting an
> > Unchecked cast warning in the compiler.
[quoted text clipped - 18 lines]
>
> Tom Hawtin

There was no way for the compiler to make sure that the object type is
correct; hence, it issues the warning.  As long as you know what you
are doing, it should be ok.
Knute Johnson - 01 Nov 2006 23:59 GMT
>>> I'm trying to read a Hashtable from an ObjectInputStream and getting an
>>> Unchecked cast warning in the compiler.
[quoted text clipped - 21 lines]
> correct; hence, it issues the warning.  As long as you know what you
> are doing, it should be ok.

Thanks.

Signature

Knute Johnson
email s/nospam/knute/

Knute Johnson - 01 Nov 2006 23:59 GMT
>> I'm trying to read a Hashtable from an ObjectInputStream and getting
>> an Unchecked cast warning in the compiler.
[quoted text clipped - 18 lines]
>
> Tom Hawtin

Thanks Tom.

Signature

Knute Johnson
email s/nospam/knute/



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.