title: Cast exception when mocking kotlin lambda callbacks in Mockk
body: <p>I am having some trouble mocking callback functions with Mockk.</p>
  
  <p>I am trying to mock a task success listener that is called like this:</p>
  
  <pre><code>collection
      .add(Item())
      .addOnSuccessListener {
          update(collection.document(it.id))
      }
  </code></pre>
  
  <p>Where the java signature for the callback would look like this:</p>
  
  <pre><code>public interface OnSuccessListener&lt;T&gt; {
      void onSuccess(T var1);
  }
  </code></pre>
  
  <p>and the signature for addOnSuccessListener looks like this</p>
  
  <pre><code>public abstract Task&lt;DocumentReference&gt; addOnSuccessListener(@NonNull OnSuccessListener&lt;DocumentReference&gt; var1);
  </code></pre>
  
  <p>My mock looks like this:</p>
  
  <pre><code>every { documentReferenceTask.addOnSuccessListener(any()) } answers {
      firstArg&lt;(DocumentReference) -&gt; Unit&gt;().onSuccess(documentReference)
      value
  }
  </code></pre>
  
  <p>I have also tried: </p>
  
  <pre><code>every { documentReferenceTask.addOnSuccessListener(any()) } answers {
      firstArg&lt;OnSuccessListener&lt;DocumentReference&gt;&gt;().invoke(documentReference)
      value
  }
  </code></pre>
  
  <p>Either way, I am receiving a cast exception like:</p>
  
  <pre><code>java.lang.ClassCastException: com.package.MyClass$addProduct$1 cannot be cast to kotlin.jvm.functions.Function1
  </code></pre>