我运行下面的代码并在返回任何内容时遇到错误();
error: incompatible types
required: Matcher <View>
found: Matcher <Object>
/**
* Perform action of waiting until UI thread is free. <p/> E.g.: onView(isRoot()).perform(waitUntilIdle());
* @return
*/
public static ViewAction waitUntilIdle(){
return new ViewAction(){
@Override public Matcher<View> getConstraints(){
return anything();
}
@Override public String getDescription(){
return "wait until UI thread is free";
}
@Override public void perform( final UiController uiController, final View view){
uiController.loopMainThreadUntilIdle();
}
}
;
}
有什么想法吗?
答案 0 :(得分:8)
anything()
不是通用方法,因此您将始终获得Matcher<Object>
。
内部anything()
使用IsAnything
类。您可以使用自己的anyView()
方法返回Matcher<View>
。
public static ViewAction waitUntilIdle(){
return new ViewAction(){
@Override public Matcher<View> getConstraints(){
return anyView();
}
@NonNull
private Matcher<View> anyView() {
return new IsAnything<>();
}
@Override public String getDescription(){
return "wait until UI thread is free";
}
@Override public void perform( final UiController uiController, final View view){
uiController.loopMainThreadUntilIdle();
}
}
;
}