title: AsyncTask with <Generics> - java.lang.Object[] cannot be cast to java.lang.String[]
body: <p>I'm trying to consume some API links. So in order to do that I have created a base <code>AsyncTask</code> class that differs by <code>SOURCE</code> and <code>RESULT</code> for each action in the app using generics.</p>
  
  <p>The problem is when I try to initialize one of the sub classes, it returns a <code>ClassCastException</code> error.</p>
  
  <p><strong>Here's the base Async class</strong></p>
  
  <pre><code>abstract class MvpBackgroundInteraction&lt;SOURCE, RESULT&gt; : AsyncTask&lt;SOURCE, Int, RESULT?&gt;(), MvpFeedContract.MvpFeedInteraction&lt;SOURCE, RESULT&gt; {
  
  protected var isWorking: Boolean = true
  protected var completeListener : MvpFeedContract.MvpCompleteListener&lt;RESULT&gt;? = null
  
  override fun start(source: SOURCE) {
      super.execute(source)
  }
  
  override fun stop() {
      isWorking = false
  }
  
  
  override fun addCompleteListener(completeListener: MvpFeedContract.MvpCompleteListener&lt;RESULT&gt;?) {
      this.completeListener = completeListener
  }
  
  override fun onPostExecute(result: RESULT?) {
      completeListener?.apply {
          if (result != null) onComplete(result) else onFailure("Result is null")
      }
      super.onPostExecute(result)
  }
  
  }
  </code></pre>
  
  <p><strong>Here's MvpFeedContract</strong></p>
  
  <pre><code>interface MvpFeedContract {
  
  interface MvpFeedInteraction&lt;SOURCE, RESULT&gt; {
      fun start(source : SOURCE)
      fun stop()
      fun addCompleteListener(completeListener: MvpCompleteListener&lt;RESULT&gt;?)
  }
  
  interface MvpCompleteListener&lt;RESULT&gt; {
      fun onComplete(result : RESULT)
      fun onFailure(message : String?)
  }
  }
  </code></pre>
  
  <p><strong>Here's one of the sub classes that returns that error</strong></p>
  
  <pre><code>class MvpDownloader : MvpBackgroundInteraction&lt;String, InputStream&gt;() {
  
  override fun doInBackground(vararg p0: String): InputStream? {
      return try {
          if (isWorking) downloadUrl(p0[0]) else null
      } catch (e : Exception) {
          Log.e("MvpParser", e.message ?: "error")
          null
      }
  }
  
  companion object {
      @Throws(IOException::class)
      private fun downloadUrl(urlString: String): InputStream? {
          val url = URL(urlString)
          return (url.openConnection() as? HttpURLConnection)?.run {
              readTimeout = 10000
              connectTimeout = 15000
              requestMethod = "GET"
              doInput = true
              connect()
              inputStream
          }
      }
  }
  }
  </code></pre>
  
  <p><strong>Here's how I'm initializing it and some similar classes</strong></p>
  
  <pre><code>private val downloader : MvpDownloader by lazy { MvpDownloader() }
  private val parser : MvpParser&lt;OBJECT&gt; by lazy { MvpParser&lt;OBJECT&gt;() }
  private val cashier : MvpCashier&lt;OBJECT&gt; by lazy { MvpCashier&lt;OBJECT&gt;(baseDao) }
  </code></pre>
  
  <p><strong>Here's the returned logcat</strong></p>
  
  <pre><code>2019-07-10 14:55:11.962 1708-1729/com.tamimattafi.degitalnomads E/AndroidRuntime: FATAL EXCEPTION: AsyncTask #1
  Process: com.tamimattafi.degitalnomads, PID: 1708
  java.lang.RuntimeException: An error occurred while executing doInBackground()
      at android.os.AsyncTask$3.done(AsyncTask.java:330)
      at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:354)
      at java.util.concurrent.FutureTask.setException(FutureTask.java:223)
      at java.util.concurrent.FutureTask.run(FutureTask.java:242)
      at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:255)
      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
      at java.lang.Thread.run(Thread.java:776)
   Caused by: java.lang.ClassCastException: java.lang.Object[] cannot be cast to java.lang.String[]
      at com.tamimattafi.degitalnomads.repository.feed.MvpDownloader.doInBackground(MvpDownloader.kt:10)
      at android.os.AsyncTask$2.call(AsyncTask.java:316)
      at java.util.concurrent.FutureTask.run(FutureTask.java:237)
      at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:255) 
      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133) 
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607) 
      at java.lang.Thread.run(Thread.java:776) 
  </code></pre>
  
  <p><strong>EDIT</strong>
  <strong>Here's my feed manager</strong></p>
  
  <pre><code>class FeedManager&lt;OBJECT&gt;(baseDao: BaseDao&lt;OBJECT&gt;) : MvpFeedContract.MvpFeedInteraction&lt;String, Boolean&gt; {
  
  private var isWorking = true
  private var completeListener: MvpFeedContract.MvpCompleteListener&lt;Boolean&gt;? = null
  
  private val downloader : MvpDownloader by lazy { MvpDownloader() }
  private val parser : MvpParser&lt;OBJECT&gt; by lazy { MvpParser&lt;OBJECT&gt;() }
  private val cashier : MvpCashier&lt;OBJECT&gt; by lazy { MvpCashier&lt;OBJECT&gt;(baseDao) }
  
  override fun start(source: String) {
      downloadFeed(source)
  }
  
  private fun downloadFeed(link : String) {
      downloader.apply {
          addCompleteListener(object :
              MvpFeedContract.MvpCompleteListener&lt;InputStream&gt; {
              override fun onComplete(result: InputStream) {
                  parseFeed(result)
              }
  
              override fun onFailure(message: String?) {
                  completeListener?.onFailure(message)
              }
  
          })
          start(link)
      }
  }
  
  private fun parseFeed(result: InputStream) {
      parser.apply {
          addCompleteListener(object :
              MvpFeedContract.MvpCompleteListener&lt;List&lt;OBJECT&gt;&gt; {
              override fun onComplete(result: List&lt;OBJECT&gt;) {
                  cashFeed(result)
              }
  
              override fun onFailure(message: String?) {
                  completeListener?.onFailure(message)
              }
  
          })
          start(result)
      }
  }
  
  private fun cashFeed(result: List&lt;OBJECT&gt;) {
      cashier.apply {
          addCompleteListener(object :
              MvpFeedContract.MvpCompleteListener&lt;Boolean&gt; {
              override fun onComplete(result: Boolean) {
                  completeListener?.onComplete(result)
              }
  
              override fun onFailure(message: String?) {
                  completeListener?.onFailure(message)
              }
  
          })
          start(result)
      }
  }
  
  
  override fun stop() {
      isWorking = false
      downloader.stop()
      parser.stop()
      cashier.stop()
  }
  
  override fun addCompleteListener(completeListener: MvpFeedContract.MvpCompleteListener&lt;Boolean&gt;?) {
      this.completeListener = completeListener
  }
  
  
  }
  </code></pre>