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 / First Aid / October 2006

Tip: Looking for answers? Try searching our database.

Getting an ArrayList back from ObjectInputStream (JDK1.5)

Thread view: 
Liz - 28 Oct 2006 22:46 GMT
Here is my code:

/**
    * fetchGremlins method to read a file and provide list
    * @param fileName String
    * @returns ArrayList<Gremlin>
    */
   public static ArrayList<Gremlin> fetchGremlins(String fileName)
       throws IOException
   {
       ObjectInputStream ois = new ObjectInputStream(
           new FileInputStream(fileName));
       ArrayList<Gremlin> list = null;
       try
       {
           list = (ArrayList<Gremlin>) ois.readObject();
       }
       catch (ClassNotFoundException ex)
       {
       }
       ois.close();
       return list;
   }
// end fragment

It works, but on compiling I get the compiler warning about unchecked
or unsafe operations.  I am assuming this is to do with generics in
Collection classes (ArrayList), and that the problem is the cast. Can
some kind person help me with the syntax to get rid of the warning and
have safe operations?
hiwa - 29 Oct 2006 09:22 GMT
> Here is my code:
>
[quoted text clipped - 26 lines]
> some kind person help me with the syntax to get rid of the warning and
> have safe operations?
For generics related warning, if it is truly benign for your
application, jsut ignore it or, since Java 6, you could use
ignore warnings annotation.
Liz - 29 Oct 2006 10:43 GMT
>> Here is my code:
>>
[quoted text clipped - 29 lines]
>application, jsut ignore it or, since Java 6, you could use
>ignore warnings annotation.

Thanks for your reply.  The application is working fine, so I shall
follow your advice to ignore the warning.  It just seems untidy.
Tor Iver Wilhelmsen - 29 Oct 2006 20:35 GMT
> For generics related warning, if it is truly benign for your
> application, jsut ignore it or, since Java 6, you could use
> ignore warnings annotation.

@SuppressWarnings("unchecked") works fine in 1.5/5-0 as well.
hiwa - 29 Oct 2006 23:37 GMT
> > For generics related warning, if it is truly benign for your
> > application, jsut ignore it or, since Java 6, you could use
> > ignore warnings annotation.
>
> @SuppressWarnings("unchecked") works fine in 1.5/5-0 as well.
Really? Well it must be back-ported into the latest release of 1.5.
Good news!


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.