title: Java: why does this work?
body: <p>It is a possibly dumb question, probability my Java is just rudimentary :-(
  but I do not understand why this works (it is actually Android code, but I think this as a general Java question).</p>
  
  <p>I do not understand how is it possible that the object <code>mySensorEventListener</code> is actually created??? </p>
  
  <ul>
  <li>I do not understand what does this code below actually do.</li>
  <li>How does this code get called???</li>
  <li>When is it called???</li>
  </ul>
  
  <h2>THIS IS THE PART I DO NOT UNDERSTAND</h2>
  
  <pre><code>public SensorListener mySensorEventListener = new SensorListener() {
  
      @Override
      public void onSensorChanged(int sensor, float[] values) {
          synchronized (this) {
          }
      }
      @Override
      public void onAccuracyChanged(int sensor, int accuracy) {
      }
  };
  </code></pre>
  
  <hr>
  
  <hr>
  
  <h2>And this is the android Activity it belongs to:</h2>
  
  <pre><code>public class RouteMapActivity extends Activity implements IRegisterReceiver {
  private SensorManager mSensorManager;
  private MapView mapView;
  
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
  
      mapView = new MapView(this, provider.getTileSource()
              .getTileSizePixels(), resProxy, provider);
  
      mSensorManager=(SensorManager)getSystemService(Context.SENSOR_SERVICE);
      mSensorManager.registerListener(mySensorEventListener,
              SensorManager.SENSOR_ORIENTATION,
              SensorManager.SENSOR_DELAY_FASTEST);
  
      setContentView(mapView);
  }
  
  public SensorListener mySensorEventListener = new SensorListener() {
  
      @Override
      public void onSensorChanged(int sensor, float[] values) {
          synchronized (this) {
              float mHeading = values[0];
              mapView.setMapOrientation(-mHeading);
          }
      }
  
      @Override
      public void onAccuracyChanged(int sensor, int accuracy) {
      }
  };
  </code></pre>