My FeedDiscussionsHeadless CMS
New
Sign in
Log inSign up
Learn more about Hashnode Headless CMSHashnode Headless CMS
Collaborate seamlessly with Hashnode Headless CMS for Enterprise.
Upgrade ✨Learn more

Why pass an interface as an argument to a function in android?

Honey Khandelwal's photo
Honey Khandelwal
·Aug 14, 2017

While learning about Event Handling I came across the the below code

Button button = (Button) findViewById(R.id.button_send);
button.setOnClickListener(new View.OnClickListener() {
    public void onClick(View v) {
        // Do something in response to button click
    }
});

I'm not understanding why an instance of anonymous class that is implementing the onClick() button is passes as an argument?

Please explain me the procedure followed above with an example