当前位置:网站首页>如何获取泛型的类型
如何获取泛型的类型
2022-06-28 11:38:00 【一杯苦芥】
@Override
public void loadImage(@NonNull Context context, @Nullable String url, @Nullable Options options, @Nullable ILoaderListener<T> listener) {
Type type = listener.getClass().getGenericInterfaces()[0];
//若type是ParameterizedType的实例, 则强转,ParameterizedType可以得到泛型的类型
if (type instanceof ParameterizedType) {
ParameterizedType pType = (ParameterizedType) type;
Type[] types = pType.getActualTypeArguments();
if (types != null && types.length > 0) {
Class clazz = (Class) types[0];
try {
Log.e("test", types[0].equals(Drawable.class));
Log.e("test", clazz.equals(Drawable.class));
} catch (Exception e) {
e.printStackTrace();
}
}
}
}边栏推荐
- Solutions to connection failures and errors when accessing mysql8 using the SSM project
- Day30 JS notes BOM and DOM 2021.09.24
- Chapter 2 do you remember the point, line and surface (2)
- AcWing 606. Average 1 (implemented in C language)
- Day34 JS notes regular expression 2021.09.29
- Day39 prototype chain and page Fireworks Effect 2021.10.13
- ProCAST finite element casting process simulation software
- Three ways to implement LRU cache (recommended Collection)
- js中的class类模式及语法 2021.11.10
- Source code analysis of ArrayList
猜你喜欢
随机推荐
Redis principle - List
[Beijing University of Aeronautics and Astronautics] information sharing for the first and second examinations of postgraduate entrance examination
fatal: unsafe repository (‘/home/anji/gopath/src/gateway‘ is owned by someone else)
Allez, Meta - Cosme, comme prévu, cette chaleur ne durera pas longtemps.
Necessary for beginners PR 2021 quick start tutorial, PR green screen matting operation method
Swin, three degrees! Eth open source VRT: a transformer that refreshes multi domain indicators of video restoration
多维度监控:智能监控的数据基础
[no title] the virtual machine vmnet0 cannot be found and an error is reported: there is no un bridged host network adapter
Cannot redeclare block range variables
Many benefits of SEO optimization are directly related to traffic
3. seat number
Deployment and optimization of vsftpd service
Build your own website (18)
QML控件类型:TabBar
零基础C语言(一)
Fruit FL studio/cubase/studio one music host software comparison
AcWing 607. Average 2 (implemented in C language)
面试步骤的面试技巧
Timestamp and date conversion "suggested collection"
AcWing 608. Poor (implemented in C language)








