类型推断失败:RecyclerViewActions.scrollTo()
来自java:
onView(withId(R.id.recyclerView)).perform(RecyclerViewActions.scrollTo( hasDescendant(withText(artistResult.getNameVariations().get(0)))));
试图转换到Kotlin:
onView(withId(R.id.recyclerView)).perform(RecyclerViewActions.scrollTo( hasDescendant(withText(artistResult.nameVariations[0]))))
我得到这个堆栈跟踪:
Error:(63, 71) Type inference failed: Not enough information to infer parameter VH in fun <VH : RecyclerView.ViewHolder!> scrollTo(itemViewMatcher: Matcher<View!>!): RecyclerViewActions.PositionableRecyclerViewAction! Please specify it explicitly.
我不完全确定我可以在哪里明确指定“它”。 以前这是因为我没有正确初始化这个值,但是在这里我调用了一个方法。 有任何想法吗?
我需要添加<RecyclerView.ViewHolder>
scrollTo
onView(withId(R.id.recyclerView)).perform( RecyclerViewActions.scrollTo<RecyclerView.ViewHolder>( hasDescendant(withText(artistResult.nameVariations[0]))))