This might be a dumb question, but I've been thinking about it for some time and I have no idea what it's really called.
So for Android, for OnClickListeners, OnTouchListeners, etc., you're allowed to do the following:
bio.setOnCancelListener(new OnCancelListener() {
public void onCancel(DialogInterface arg0) {
// TODO Auto-generated method stub
}
});
Pretty much making a new class inline. What is this called in Java or is it an Android specific thing? Basically, what's going on when this happens? Are you pretty much creating an inner class that implements OnCancelListener since On[blah]Listeners are interfaces?
Thanks!
You are correct. You are creating an anonymous inner class which will implement the methods required by OnCancelListener.
See: How are Anonymous (inner) classes used in Java?
They are in Java.. They are called Anonymous classes since they don't have any name.
This is how java tries to combat its inability to support closures,A popular language feature. .
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With