4

I want to use ArgumentCaptor in kotlin.

What I've done :

val c := ArgumentCaptor<List<MyClass>, 
List<MyClass>>.forClass(List<MyClass>::class.java)

but it says

Only classes are allowed on the left hand side of a class literal

ephemient
  • 198,619
  • 38
  • 280
  • 391
egon12
  • 780
  • 5
  • 22
  • syntax error, change `:=` to `=' – Les Nov 09 '17 at 12:56
  • "Type Erasure". Take a look at this [SO answer](https://stackoverflow.com/questions/39679180/kotlin-call-java-method-with-classt-argument) for a very good explanation. – Les Nov 09 '17 at 13:09

1 Answers1

10
ArgumentCaptor<List<MyClass>> c = ArgumentCaptor.forClass(List<MyClass>.class);

doesn't compile in Java either, because at runtime <MyClass> isn't part of the type due to erasure.

Instead, consider using com.nhaarman:mockito-kotlin which wraps Mockito with an API more suitable for use from Kotlin.

val c = argumentCaptor<List<MyClass>>()
ephemient
  • 198,619
  • 38
  • 280
  • 391