Mam taki kod
static <T> boolean serialization(T obj)
{
try {
if(obj instanceof Movie) {
ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("movies.ser", true));
oos.writeObject(obj);
oos.close();
}
else if(obj instanceof Series) {
ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("series.ser", true));
oos.writeObject(obj);
oos.close();
}
return true;
} catch (FileNotFoundException e) {
System.out.println("Can not find the file. Please try again later...");
return false;
} catch (IOException e) {
System.out.println("Unable to save file. Please try again later...");
return false;
}
}
Sprawa polega na tym, że klasa Series dziedziczy z klasy Movie, a co za tym idzie należy do instancji klasy Movie i mam mały problem z skonstruowaniem warunku. Jak można to rozwiązać bez usuwania dziedziczenia?