title: Some casting issues from Father to Son that I can't get to figure out:
body: <p>I have the following abstract class:</p>
  
  <pre><code>public abstract class AbstractService extends Service {
  
  @Override
  public IBinder onBind(Intent intent) {
      return null;
  }
  }
  </code></pre>
  
  <p>This class is extended by two other classes:</p>
  
  <pre><code>public abstract class AbstractMessengerService extends AbstractService {
  static final int MSG_REGISTER_CLIENT = 9991;
  static final int MSG_UNREGISTER_CLIENT = 9992;
  
  ArrayList&lt;Messenger&gt; mClients = new ArrayList&lt;Messenger&gt;(); // Keeps track of all current registered clients.
  final Messenger mMessenger = new Messenger(new IncomingHandler()); // Target we publish for clients to send messages to IncomingHandler.
  
  private class IncomingHandler extends Handler { // Handler of incoming messages from clients.
      @Override
      public void handleMessage(Message msg) {
          switch (msg.what) {
              case MSG_REGISTER_CLIENT:
                  Log.i("MyService", "Client registered: " + msg.replyTo);
                  mClients.add(msg.replyTo);
                  break;
              case MSG_UNREGISTER_CLIENT:
                  Log.i("MyService", "Client un-registered: "+msg.replyTo);
                  mClients.remove(msg.replyTo);
                  break;
              default:
                  //super.handleMessage(msg);
                  onReceiveMessage(msg);
          }
      }
  }
  
  @Override
  public void onCreate() {
      super.onCreate();
  
      onStartService();
  
      Log.i("MyService", "Service Started.");
  }
  
  @Override
  public int onStartCommand(Intent intent, int flags, int startId) {
      Log.i("MyService", "Received start id " + startId + ": " + intent);
      return START_STICKY; // run until explicitly stopped.
  }
  
  @Override
  public IBinder onBind(Intent intent) {
      return mMessenger.getBinder();
  }
  
  @Override
  public void onDestroy() {
      super.onDestroy();
  
      onStopService();
  
      Log.i("MyService", "Service Stopped.");
  }
  
  protected void send(Message msg) {
      for (int i=mClients.size()-1; i&gt;=0; i--) {
          try {
              Log.i("MyService", "Sending message to clients: "+msg);
              mClients.get(i).send(msg);
          }
          catch (RemoteException e) {
              // The client is dead. Remove it from the list; we are going through the list from back to front so this is safe to do inside the loop.
              Log.e("MyService", "Client is dead. Removing from list: "+i);
              mClients.remove(i);
          }
      }
  }
  
  public abstract void onStartService();
  public abstract void onStopService();
  public abstract void onReceiveMessage(Message msg);
  
  }
  </code></pre>
  
  <p>And:</p>
  
  <pre><code>public abstract class AbstractAIDLService extends AbstractService {
  private Handler handler;
  ArrayList&lt;Messenger&gt; mClients = new ArrayList&lt;Messenger&gt;(); // Keeps track of all current registered clients.
  
  private final IRemoteService.Stub mBinder = new IRemoteService.Stub() {
      public int getPid(){
          return  android.os.Process.myPid();
      }
  
      @Override
      public void setActivityColor(String color, long startTime) throws RemoteException {
          long elpsedTime = (System.nanoTime() - startTime) / (1000 * 1000);
          showElpesedTime(String.valueOf(elpsedTime));
      }
  
      public void basicTypes(int anInt, long aLong, boolean aBoolean,
                             float aFloat, double aDouble, String aString) {
          // Does nothing
      }
  };
  
  private void showElpesedTime(final String time)
  {
      handler.post(new Runnable() {
          public void run() {
              Toast toast = Toast.makeText(AbstractAIDLService.this, "Time passed reaching the server: "+time+"ms", Toast.LENGTH_SHORT);
              toast.show();
          }
      });
  }
  
  @Override
  public void onCreate() {
      super.onCreate();
      onStartService();
      Log.i("MyService", "Service Started.");
  }
  
  @Override
  public int onStartCommand(Intent intent, int flags, int startId) {
      Log.i("MyService", "Received start id " + startId + ": " + intent);
      return START_STICKY; // run until explicitly stopped.
  }
  
  @Override
  public IBinder onBind(Intent intent) {
      return mBinder;
  }
  
  
  @Override
  public void onDestroy() {
      super.onDestroy();
  
      onStopService();
  
      Log.i("MyService", "Service Stopped.");
  }
  
  public abstract void onStartService();
  public abstract void onStopService();
  public abstract void onReceiveMessage(Message msg);
  
  }
  </code></pre>
  
  <p>Now I created a <code>ServiceManager</code> class which is a factory class that I want to create concrete version of those class and passed them to this manager class. I have a constructor in this ServiceManager:</p>
  
  <pre><code>public class ServiceManager {
  
  private static final String TAG = ServiceManager.class.getSimpleName();
  private Class&lt;? extends AbstractService&gt; mServiceClass;
  
    public ServiceManager(Context context, ServiceType type, Class&lt;? extends AbstractService&gt; serviceClass, Handler incomingHandler) {
      this.mActivity = context;
  
      this.mIncomingHandler = incomingHandler;
      if (type.equals(ServiceType.AIDL)) {
          this.mServiceClass = (AbstractAIDLService) serviceClass;
      } else if (type.equals(ServiceType.MESSENGER)) {
          this.mServiceClass = (AbstractMessengerService) serviceClass;
      }
  
      if (isRunning()) {
          doBindService();
      }
  }
  </code></pre>
  
  <p>But for some reason, those lines: <code>this.mServiceClass = (AbstractAIDLService) serviceClass;</code>, <code>this.mServiceClass = (AbstractMessengerService) serviceClass;</code> give me a casting problem. How can this be done?</p>