本文介紹了Mockito.any() 通過泛型接口的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習吧!
問題描述
是否可以使用泛型傳遞接口的類型?
is it possible to pass the type of an interface with generics?
界面:
public interface AsyncCallback<T>
在我的測試方法中:
Mockito.any(AsyncCallback.class)
將 <ResponseX>
放在 .class
后面或為 .class
不起作用.
Putting <ResponseX>
behind or for .class
didnt work.
推薦答案
有一種類型安全的方法:使用 ArgumentMatchers.any()
并用類型限定它:
There is a type-safe way: use ArgumentMatchers.any()
and qualify it with the type:
ArgumentMatchers.<AsyncCallback<ResponseX>>any()
這篇關(guān)于Mockito.any() 通過泛型接口的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!
【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!