Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

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
15,196 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?