Answer the question
In order to leave comments, you need to log in
Is it possible to have a data structure of heterogeneous elements in Java?
Good afternoon. Does anyone know how to put heterogeneous elements into a data structure?
There are several date classes, they must be returned in one request. I would like something like List<Class1,Class2>.
this possible? So far, it comes to my mind to create a wrapper class and return this class already. Maybe there is an easier way?
Answer the question
In order to leave comments, you need to log in
Just List without Generic (Raw types). List list = new ArrayList();
But this is, will your client read such data? Do these classes have no common class or interface? If these are completely different entities, then I would make a wrapper (DTO-class) with different fields.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question