Instantiating Java object with a passed in method
Posted
by
superluminary
on Stack Overflow
See other posts from Stack Overflow
or by superluminary
Published on 2012-06-12T10:26:37Z
Indexed on
2012/06/12
10:40 UTC
Read the original article
Hit count: 171
java
|functional-programming
It's been a few years since I've been heavily into Java. Coming back to it I'm seeing this pattern all over the place:
ratingBar.setOnRatingBarChangeListener(new OnRatingBarChangeListener() {
public void onRatingChanged(RatingBar ratingBar, float rating, boolean fromUser) {
// do work
}
});
This looks more like Functional programming to me. It's a nice pattern but how is it possible to pass a method like this? In the old days a class was a class, and once compiled there was little you could do to it.
My questions are:
- Can anyone let me know what this pattern is called?
- How can I write a class that can be instantiated in this way.
- Are there any other useful examples of functional patterns that have made their way into Java?
- What do I need to Google to read more about this?
Thanks.
© Stack Overflow or respective owner