Un-Java-like? How so? The ability to define a local instance of a Comparator which understands local state, which you can pass off to a sorting function to sort things in a customized way, is very Java. That's been around since the beginning.
You're certainly right, there are other ways to do it. But this lets you handle arbitrary stuff.
Where C passes function pointers, Java passes objects implementing an expected interface, which may or may not have been defined on the fly. Java anonymous classes aren't quite as good as Lisp closures, mostly because they can only close over "final" variables, but they add a measure of convenience (and reduce, for once, the amount of code you have to type to get that functionality).
no subject
Date: 2008-03-10 04:28 pm (UTC)You're certainly right, there are other ways to do it. But this lets you handle arbitrary stuff.
Where C passes function pointers, Java passes objects implementing an expected interface, which may or may not have been defined on the fly. Java anonymous classes aren't quite as good as Lisp closures, mostly because they can only close over "final" variables, but they add a measure of convenience (and reduce, for once, the amount of code you have to type to get that functionality).