Java Java Data Structures Efficiency! Building the Model

Andre Kucharzyk
Andre Kucharzyk
4,479 Points

This might be a dumb question, but how do we know what kind of objects interface can take?

This might be a dumb question, but how do we know what kind of objects interface can take?

private List<Song> songs; <-- how do we know that we can put Songs there?

Yanuar Prakoso
Yanuar Prakoso
14,816 Points

First it will be better if you refine your question to be What kind of objects does a List, Set, Map interface can take? You need to be specific here since interface has broad definition.

The answer is theoretically if it is an object it can be put in List, Map, and/or Set.

Andre Kucharzyk
Andre Kucharzyk
4,479 Points

I guess my question is why can we put any object in List/Map/Set? Where in code is that determined?