D
D
DDwrt1002019-06-25 12:15:49
Java
DDwrt100, 2019-06-25 12:15:49

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

2 answer(s)
F
Frozen Coder, 2019-06-25
@DDwrt100

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.

E
EVGENY T., 2019-06-25
@Beshere

List<?>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question