Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

help with a weird block

 
Daniel Loranz
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is me --->

I need help understanding the following block structure.



I see ... Class.method(arguments, very strange things embedded in argument list);
Very disturbing. Please help.

Thanks.


[ July 25, 2008: Message edited by: Daniel Loranz ]

Hmmm - angle brackets don't appear to display correctly even inside code tags. I'll sub [ and ] for angle brackets.
[ July 25, 2008: Message edited by: Daniel Loranz ]
 
Brian Holsenbeck
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Look at the Collections class on the api:

http://java.sun.com/j2se/1.5.0/docs/api/

It has a sort routine that wants a list, and something that implements the Comparator interface:

sort(List<T> list, Comparator<? super T> c)

You *could* create a class that implements Comparator outside the call; new an instance of that class; then pass the new instance of that class. This, however, lets you create a class on the fly (I think it's called an anonymous class; someone will call me on that if I'm wrong, I'm sure), and pass a new instance of that anonymous class as the comparator. The Comparator only wants a way to compare 2 instances of your list.

Hope the above makes sense. I'd have trouble writing it, but I *think* I understand it.

Hello from a new cattle drive guy, btw! I've just sent in 1b recently. I'm sure I'll have lots of questions posted soon.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic