Witam. Chciałbym aby funkcja getFromFile czytała z pliku obiekty będące listą i przypisywala je do kolejno zmiennych animals i employees.
Jednak skoro w javie nie ma przekazywania przez referencje, a przez wartość, to nie mam pomysłu co zrobić.
klasa Shelter
List<Animal> animals2 = new ArrayList<>();
List<Employee> employees2 = new ArrayList<>();
FileWorker.getFromFile(animals2, employees2);
animals2.forEach(a -> System.out.println(a));
klasa FileWorker
static public void getFromFile(List<Animal> animals, List<Employee> employees) {
try(ObjectInputStream os = new ObjectInputStream(new FileInputStream("shelterinfo.bin"))) {
animals = (ArrayList<Animal>) os.readObject();
employees = (ArrayList<Employee>) os.readObject();
} catch (FileNotFoundException e) {
System.out.println("Can not find the file");
} catch (IOException e) {
System.out.println("Can not read information from the file");
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}