Problem reading ArrayList of String[] from serialized file
Using Java 6.0 and getting unchecked conversion warning on an ArrayList cast when reading an ArrayList of String[] from a serialized file at compile time.
The general thrust of the code follows:
private static java.util.List<String[]> databaseAlias = new ArrayList<String[]>(); // class level declaration - obviously
// method in the class writes ArrayList of String[] to serialized file - no compile errors or warnings
private static void writeDatabaseAlias(java.util.List dbListing)
{
try
{
ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("c:\\program files\\<prog dir>\\addresses.ser"));
oos.writeObject(dbListing);
}
catch(IOException ioe)
{
ioe.printStackTrace();
}
}
// method reads the ArrayList from the serialized file and this is where I'm getting the compile warning -
// I'd like it to be correctly type casting since that's the goal...
private java.util.List<String[]> readDatabaseAlias()
{
File serFile = new File("c:\\program files\\<prog dir>\\addresses.ser");
try
{
if (serFile.exists())
{
ObjectInputStream ois = new ObjectInputStream(new FileInputStream(serFile));
//********* Get an unchecked conversion warning on the following line *********
databaseAlias = (ArrayList) ois.readObject();
}
else
{
JOptionPane.showMessageDialog(null, "No Data AliasesFound"), JOptionPane.ERROR_MESSAGE);
}
}
catch (ClassNotFoundException cnfe)
{
cnfe.printStackTrace();
}
catch (IOException ioe)
{
ioe.printStackTrace();
}
return databaseAlias;
}
Noting the asterisked line of code above - and after looking through the Generics tutorial and other info online - I've tried to clear the warning with the following lines of code but to no avail:
databaseAlias = (ArrayList<String[]>) ois.readObject(); // gens an error msg
databaseAlias = <String[]>(ArrayList) ois.readObject(); // gens an error msg
Any thoughts or ideas? This should be a no-brainer, I'm sure, but I'm quite stumped. And no, the static modifier on the last method call is not an issue...

