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 - Retired Efficiency! Queueing

questions about the <Song> object that we pass to queue and to other interfaces.

Hi, in this examples:

 private Queue<Song> mSongQueue;

why we pass <Song> to the mSongQueue?, i understand that mSongQueue is of type "Song" but im not 100% sure that im right about this. We pass <Song> because in the Song class contains all the information, properites, methods and etc about the artist,title and videoUrl?

Song artistSong = promptSongForArtist(artist);

same goes for this example? why artistSong is of type Song?

and here

public SongBook()
  {
    mSongs = new ArrayList<Song>();
  }

if for some reason we wanted to use the properites of SongBook like we did in the KaraokeMachine constructor i understand that we need to create a new instance aka access point to the class but in interfaces i just want a clarification..

Tonnie Fanadez Brendan Whiting

If u can clear this up i will appreciate this.

1 Answer

Tonnie Fanadez
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Tonnie Fanadez
UX Design Techdegree Graduate 22,796 Points

Hello noob developer

In this context we are using Queue to store or to carry song object inside it. The Queue enables us to add new songs, get the total number of songs in the queue or retrieve what the first song on the Queue.

mSongs = new ArrayList<Song>

You don't even have to specify the Song Object between the diamond brackets of the ArrayList since it is already defined on the Queue

Properties and Method of Song Class are not important here.