Getting an ArrayList back from ObjectInputStream (JDK1.5)
- From: Liz <liz@xxxxxxxxxxxxxxxxxxxxxxx>
- Date: Sat, 28 Oct 2006 22:46:09 +0100
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?
.
- Follow-Ups:
- Prev by Date: Re: Running a Java Program
- Next by Date: Re: Running a Java Program
- Previous by thread: JDK vs JRE
- Next by thread: Re: Getting an ArrayList back from ObjectInputStream (JDK1.5)
- Index(es):