title: Method definition passed as argument
body: <p>I saw this code when looking at an Android example:</p>
  
  <pre><code>@Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
  
      EditText editNumber;
      Button btnCall = (Button) this.findViewById( R.id.btnCall);
  
      editNumber = (EditText) this.findViewById(R.id.editNumber);
      btnCall.setOnClickListener(
              new OnClickListener() {
  
                  public void onClick(View v) {
                      call();
                  }
              });
      // ...
  }
  </code></pre>
  
  <p>Here:</p>
  
  <pre><code>new OnClickListener() {
      public void onClick(View v) {
          call();
      }
  }
  </code></pre>
  
  <p>is passed to <code>setOnClickListener()</code> as a parameter. What I don't understand is what code inside <code>{...}</code> does here? if <code>new OnClickListener()</code> calls the constructor, and the constructor returns an object, yes, object can be passed to method as a parameter, but what is:</p>
  
  <pre><code>{
      public void onClick(View v) {
          call();
      }
  }
  </code></pre>
  
  <p>doing here? It looks like a method definition?</p>
  
  <p>Thanks a lot for the help!</p>