Mockito.any() 通过与泛型的接口 [英] Mockito.any() pass Interface with Generics

查看:33
本文介绍了Mockito.any() 通过与泛型的接口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以通过泛型传递接口的类型?

is it possible to pass the type of an interface with generics?

界面:

public interface AsyncCallback<T>

在我的测试方法中:

Mockito.any(AsyncCallback.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()

这篇关于Mockito.any() 通过与泛型的接口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆