Saving ArrayList to File

Is it possible to write an ArrayList holding an unknown type to a file and read it back later? Say I have an ArrayList of apples and and ArrayList of thumbtacks. I know it's either one or the other. Apples and thumbtacks don't have a common ancestor besides Object. Rather than write a method to handle each type, I'd like to just have one method that will handle any type. I've read about generics, but nothing I do is working. Apple and ThumbTack are both Serializable.

Code is just an example to hopefully show you what I'm trying to do. I understand that there's no way to know when I read a file that it will be of the type I'm looking for and could be an unsafe cast. But how do I fix it? Or is it just a warning and I can believe that my application will only be dealing with known types and ignore the warning?