Tell me, please, how to return a List containing objects of two classes?
There are objects of the classes Profession and Subject
List<Profession> и List<Subject> How in a method to return them one list?
Tell me, please, how to return a List containing objects of two classes?
There are objects of the classes Profession and Subject
List<Profession> и List<Subject> How in a method to return them one list?
Alternatively, use the Object class:
List<Object> objList = new ArrayList<>(); objList.addAll(professionList); objList.addAll(subjectList); Another way is to create a class that encapsulates these two lists:
class Storage { private List<Profession> professions; private List<Subject> subjects; public Storage(List<Profession> professions, List<Subjects> subjects) { ... } ... } And further we return List<Storage> .
In general, most likely, your method is implemented incorrectly, since it is required to return lists of two different classes.
Source: https://ru.stackoverflow.com/questions/525582/
All Articles