Mapping one collection of objects into another collection of objects

22 views Asked by At

I have a collection of objects, let's say models, that all implement the same interface. They are all stored in a literal collection. I would like to map them now to different objects and the mapping should happen solely based on the type of the model from the collection.

To explain using a noob solution as an example, I could loop over the collection, check the type of the object using instanceof, and based on that select the class of the object I want to map it to and initiate the mapping. So that is the wrong solution, what is the right solution?

0

There are 0 answers