Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

only classes are allowed on the left hand side of a class literal when using Mockito and kotlin

I used Android studio's conversion tool to convert existing java test class.

I am getting this error :

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

Here is the test case used :

Java

doAnswer(answerVoid(
            (OnDataListListener<List<BEntity>> myCallback) -> myCallback.onSuccess(mList))).when(
            mInteractor).performGetBList(any(OnDataListListener.class), anyBoolean());

Kotlin

doAnswer(answerVoid { listener: OnDataListListener<List<BEntity>> ->
      listener.onSuccess(
          emptyList())
    }).`when`<DragonInteractor>(mInteractor)
        .performGetBList(any<OnDataListListener>(OnDataListListener<*>::class.java),
            anyBoolean())

So how to use generic params in this case? Thanks.

like image 680
Mohamed ALOUANE Avatar asked Aug 16 '17 11:08

Mohamed ALOUANE


1 Answers

Just use OnDataListListener::class.java.

The reason why the angle brackets are not required (and not allowed) in a class reference expresison is that class references are completely agnostic of generics, there are no different class references for generic specializations of a class.

like image 54
hotkey Avatar answered Oct 29 '22 10:10

hotkey