• Post Reply Bookmark Topic Watch Topic
  • New Topic

Parameter help  RSS feed

 
Matthew Chen
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey guys, So I have this class called Theater and within it, there is a field:

private Queue<Customer> queue;

I also have a class called Customer. I know there is a correlation between the field in Theater and my Customer Class but I have no idea what it is

Could someone explain to me what the Angled Brackets mean? and what connection does the Queue have with the class???

-Jdakdoa
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Matthew Chen wrote:Hey guys, So I have this class called Theater and within it, there is a field:

private Queue<Customer> queue;

I also have a class called Customer. I know there is a correlation between the field in Theater and my Customer Class but I have no idea what it is

Could someone explain to me what the Angled Brackets mean? and what connection does the Queue have with the class???

-Jdakdoa


It's one of the ways Java provides to ensure compile-time type-safety. What that means and how it works in general is too broad to explain here, since the exact semantics of the parameterization tpye is determined by the defining class, but you can get more information on that by googling for java generics tutorial.

What it means for you the programmer in this specific case is that the you will only be allowed to add Customer objects to that Queue--no Strings, Integers, or anything else--and that when you extract anything from that queue, the compiler knows it will be a Customer, so you don't need to cast it.
 
Matthew Chen
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Alot! I understand now!
 
Campbell Ritchie
Marshal
Posts: 56536
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And welcome to the Ranch
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!