• Post Reply Bookmark Topic Watch Topic
  • New Topic

What is greater than less than?  RSS feed

 
R Jarman
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It wouldn't let me post a title with <> in it.

So now based on advise, I'm reading the Sun docs on collections. (I haven't used Java for a few versions). There is a code snipet using an Iterator to parse a Collection. This is the code:

static void filter(Collection<?> c) {
for (Iterator<?> it = c.iterator(); it.hasNext(); )
if (!cond(it.next()))
it.remove();
}

What is <?> ? I don't remember ever using <>. Is that a way of type casting? If so, what does ? stand for?
 
Keith Lynn
Ranch Hand
Posts: 2409
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The angle brackets are used to specify the type parameters to a generic class or method.

The ? is a wildcard.

So Collection<?> means a Collection containing anything.
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by R Jarman:
...I haven't used Java for a few versions...

"Generics" were just introduced with Java 5.0. Try this Generics Tutorial to get up to speed.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!